in reply to Glob seekpointer

This might work for you provided your files are each less than a couple of hundred MB. If that's the case it should a bit quicker than your algorithm above.

#! perl -slw use strict; my( $dir, $glob, $fieldsFile ) = @ARGV; open FIELDS, '<', $fieldsFile or die $!; chomp( my @fields = sort{ length( $b ) <=> length( $a ) } do{ local $/ = "\n"; <FIELDS> } ); close FIELDS; my $re_fields = qr"(@{[ join'|', map{ quotemeta } @fields ]})"; print "@$_" for map { open my $fh, '<:raw', $_ or warn "$_ : $!"; do{ local $/; <$fh> } =~ $re_fields ? [ $1, $_ ] : () } glob "$dir/$glob"; __END__ P:\test>type fields.txt map grep List::Util P:\test>mgrep . *.pl fields.txt List::Util ./200083.pl List::Util ./250802.pl map ./282393.pl map ./306836-trietest.pl map ./308236.pl map ./324513.pl map ./328326.pl map ./330590.pl List::Util ./332124.pl map ./333094.pl map ./333937.pl grep ./334482.pl grep ./335040.pl map ./336125.pl List::Util ./336580.pl ...

You can also supply CON (or maybe /dev/tty on *nix?) in place of the last parameter to have it take the search terms from the keyboard:

P:\test>mgrep . *.pl CON min max ^Z max ./200083.pl max ./250802.pl min ./333502.pl min ./335040.pl min ./336125.pl ...

Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.