'ab' =~ /(? a (? b))/x; print "$_ => $+{$_}\n" for (keys(%+)); # 'A => ab' # ... nothing, thats it print "$+{'A'}\n"; # 'ab' print "$+{'B'}\n"; # 'b'