while($string=~m/(?(\w+)?(\w+))/g) { print "Match : $1 GroupName: "; }