if ("abbbbbc" =~ /(b*?)(b*?)c/) { print("\$1 eq '$1'\n"); # $1 eq '' print("\$2 eq '$2'\n"); # $2 eq 'bbbbb' } else { print("No match\n"); }