in reply to Faster way to do this?

my $string = 'IIIIIIIIIIIMMMMMMMMMMMMOOOOOOOOOOOOMMMMMMMMMIIIIIIIII'; my $count = () = $string =~ /M/g; print $count;

You can also use the tr operator.

my $count = $string =~ tr/M//;