in reply to number of matches
$count = () = $str =~ /PATTERN/g; # Non-overlapping mat +ches $count = () = $str =~ /(?=(PATTERN))/g; # Overlapping matches $count = 0; $str =~ /PATTERN(?{$count ++})(?!)/; # All matches [download]