Hopefully, this will help:
Code:
while ($string =~ m/(M+)/gi) {
print "Found '$&'";
}
The important part being
m/(M+)/gi which is a regular expression matching one or more letter Ms (upper and/or lower case) together. After the last slash (/) is the
global modifier (matches all instances of the M groups) and the case-
insensitive modifier (take the 'i' out to make the search case-sensitive).