in reply to Interpolating $1 within a variable

Oops I missed the fact that you lose the comma doing that - yellow is not the best highlight color BTW. This preserves the comma for you:

$_=q(ab cdefg); $x=q($1,); s#(^\w+)# my $sub = $1; $x=~s/\$1/$sub/; $x #e; print;

Update

That will permanently change the value in $x which you probably don't want so I should have used a scoped temp var like this:

s#(^\w+)# my $sub = $1; (my $subx = $x) =~ s/\$1/$sub/; $subx #e;

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print