You're confusing string literals (code) and strings (values).
In the source, "$2$1" is a string literal. It results in a string made up of the values of $1 and $2.
my $p = "$2$1"; # my $p = $2.$1; # Doesn't change the value of $2 or $1.
In the source, "$ARGV[0]" is a string literal. It results in a string made up of the value of $ARGV[0].
my $p = "$ARGV[0]"; # my $p = "".$ARGV[0]; # Doesn't change the value of $ARGV[0].
If you want process the value of a variable for $1 and $2 and replace them, you are trying to implement a templating system. There's a one that matches your specs called String::Interpolate.
use String::Interpolate qw( interpolate); my $t = '$1$2'; or my $t = $ARGV[0]; my $p = interpolate($t);
In reply to Re: Interpolation of capture buffers not working when regex stored in variable
by ikegami
in thread Interpolation of capture buffers not working when regex stored in variable
by jacklh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |