open my $p, "< ". shift @ARGV or die "could not open pattern file: $!"; my @patterns = <$p>; chomp @patterns; for my $filename (@ARGV) { open my $f, "< $filename" or die "could not open $filename: $!"; my @lines = <$f>; for my $pattern (@patterns) { printf "%s has %d matches for pattern /%s/\n", $filename, scalar(grep /$pattern/, @lines), $pattern; } }