http://www.perlmonks.org?node_id=1055870


in reply to Named capture backreferences cannot be used in character classes?

One workaround is to use a negative look-ahead plus a dot instead of a negated character class:

use strict; use warnings; use 5.010; for (qw/'abc' "abc" 'abc"/) { if (/(?<FQ>['"])(?<content>(?:(?!\k<FQ>).)+)\k<FQ>/s) { say $+{content}; } else { say "Not matched: $_"; } } __END__ abc abc Not matched: 'abc"