#!/usr/bin/perl use strict; use warnings; use Term::ANSIColor qw/:constants/; my $input = shift; die "Usage: $0 [files...]\n" if not defined $input; my $regexp = eval { qr/$input/o }; die "Pattern error: $@\n" if $@; while (my $line = <>) { chomp $line; if ($line =~ m/$regexp/) { for my $i (0 .. $#+) { my ($start, $stop) = ($-[$i], $+[$i]); print q/$/ , $i ? $i : q/&/ , q/: / , substr($line, 0, $start) , BOLD, , ($stop - $start > 0) ? (RED, substr($line, $start , $stop - $start)) : (BLUE, q/|/) , RESET , substr($line, $stop) , qq/\n/; } } }