#!/perl/bin/perl use strict; use warnings; my @files = ; my $total = 0; foreach my $file ( @files ) { open my $file_h, '<', $file or die "Can't open $file: $!"; while ( <$file_h> ) { if (/\b120[347]\b/) { print "$file $_"; $total++; } } } print "No files matched.\n" unless $total;