$str = "ABCDEFGHIJKLM"; while ($str =~ /(BC|GH|LM)/g) { print "matched $1\n"; } #### matched BC matched GH matched LM