while(<>) { $line = chomp; $count++ if ($line =~ /foo/); } print $count;