my ($quoted,$match) = $string =~ /(<)?(ab)(?(1)>)/x; # or: my $match = ($string =~ /(<)?(ab)(?(1)>)/)[1];