$ perl -e 'my $string = "foobarfoofoobarfoo"; my $count = $string =~ s/foo/foo/g; print $count;' 4