in reply to Re^3: Regexp substitution using variables
in thread Regexp substitution using variables

> but I can't get back-references,

This works for me

DB<44> $pat='(x)\1' DB<45> $mod='i' DB<46> 'xX' =~ /(?$mod)$pat/; say "$&:$1" xX:x DB<47>

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^5: Regexp substitution using variables
by MikeTaylor (Sexton) on Nov 26, 2020 at 10:34 UTC
    Sorry, I think I was using the term "back-reference" incorrectly. I didn't mean referring back within the pattern to something earlier in the pattern, but referring in the substitution string to a captured sub-expression of the pattern. Something like s/(foo|bar)/He said "$1"/.