#!/usr/bin/perl use warnings; use strict; use File::Basename; if (@ARGV < 1) { print "usage: cat | ", basename($0), " \n"; exit 2; } my $pattern = shift; my $line_counter = 0; while (<>) { $line_counter++; my $line = $_; chomp($line); if (my @matches = $line =~ /$pattern/) { if ($#- != 0) { my $counter = 0; if (scalar(@matches) == 1) { printf "\e[0;32mmatched group\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $matches[0], $line_counter, $line; } else { printf "\e[0;32mmatched %d groups\e[0m in line %d (%s):\n", scalar(@matches), $line_counter, $line; for my $match (@matches) { print "\t".$counter++.": \e[0;38;5;12m".$match."\e[0m\n"; } } } else { printf "\e[0;32mmatched\e[0m \e[0;38;5;12m%s\e[0m in line %d (%s)\n", $&, $line_counter, $line; } } else { #print "\e[0;31mno match\e[0m\n"; } }