/usr/bin/perl -n BEGIN{ @ARGV=qw(the files you want to process); } push @files, $ARGV and close ARGV if /^pattern/; END{ print "matching files @files\n" }