#! /usr/local/bin/perl use strict; use warnings; my $target = shift; $target = qr/$target/; for my $file (@ARGV) { my $str = do {local $/ = undef; open my $in, '<', $file; <$in>}; next unless $str =~ /$target/; my $current = 1; while ($str =~ /((?:[^\n]*?\n)*?)(.*?$target[^\n]*)/g) { $current += $1 =~ tr/\n/\n/; print "$file($current): $2\n"; } }