http://qs1969.pair.com?node_id=11124218

MikeTaylor has asked for the wisdom of the Perl Monks concerning the following question:

I have a string $value that I want to transform by regexp substitution. But the pattern, replacement and flags are known only at run-time. They are specified by $pattern, $replacement and $flags. So I want to do something like
$value =~ s/$pattern/$replacement/$flags;
but of course that doesn't work as intended. Or perhaps something like this, if I could only find the right class name:
my $re = new Regexp($pattern); my $value = $re->substitute($value, replacement, $flags);
There has to be way to do this ... right?