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