Your $1 gets interpolated too early. What you really need is a templating system, but you can use the following in the meanwhile:
sub foo { (my $text = $_[0]) =~ s/$_[1]/eval $_[2]/e; print $text; } foo("This is test 1\n", qr/test (.*)/, '"fish $1"');
(Insert notice of hazards of using eval EXPR here.)
In reply to Re: How do I pass $1 to s///?
by ikegami
in thread How do I pass $1 to s///?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |