$pattern = shift; $file = shift; open(MAT, "<$file") or die "bad file name"; $text = ; while($text =~ /\Q$pattern\E/g) { $x += 1; } print "found $x matches\n"; close(MAT);