in reply to Re: Counting text strings
in thread Counting text strings

Or something slightly different yet the same
while ( <FILE> ) { $count += $_ =~ s/foo/foo/g; print "$count so far\n"; }
If you do $count = $_ =~ s/foo/foo/g; $count will have how many replacements happened on that line. Instead of using a temp variable to hold it, I simply += it as we go.. I should probably benchmark it to see how it compares, but its late.

/* And the Creator, against his better judgement, wrote man.c */