in reply to Exec'ing a regex stored in a scalar variable
and to use it in a substitution command, just plug it in:$search = qr/pattern/;
To store the entire substitution, I'd go with a subref:s/$search/replace/g;
my $rep = sub { $_[0] =~ s/a/b/g }; my $string = "abc"; $rep->($string); print "$string\n";
|
|---|