while($string=~/(M+)/g) { ($start, $end) = ($-[0], $+[0]); print $start."\t".$end."\n"; }