while ( ) { $count += $_ =~ s/foo/foo/g; print "$count so far\n"; }