use Data::Dump qw( pp ); my $str = < qr/ " (?: \\\\ | \\" | [^"] )* " /x, Eily => qr/ " (?: [^"\\] | \\. )* " /x); $str =~ /$re{$_}/ and say "$_ found $&" or say "$_ found nothing" for keys %re;