in reply to Re^3: RegExp substitution
in thread RegExp substitution

Hello HereandThere, welcome to the Monastery. Hmm, did you try this code that you posted?
$_="FourThreeTwoOne, Three, Four, One, Two"; $1="Three"; $second="&&&&"; s/$2/$second/g; print;
I am pretty sure it cannot work. For a start, $1 is a read-only value that can be set only by a regex.
$1="Three";
I do not think that the perl compiler accepts that, but even if it did, it should not be done. In my view, $1 is a special variable that should be kept for just one single purpose: the first capture in a regex.
s/$2/$second/g;
This makes even less sense, since $2 has not been set anywhere, it is undefined, there is just no way this is gonna work. In addition, I would suggest that if you set $_ to something, you first localize it within some lexical block:
{ local $_="FourThreeTwoOne, Three, Four, One, Two"; # ... }
Furthermore, you should probably have these pragmas at the top of your script:
use strict; use warnings;
and they would force you to rewrite the third line of your code as:
my $second="&&&&";
Finally, I don't even understand what your code is supposed to demonstrate to the OP. Well, to tell the truth, if you were not so new on this forum, I would probably down vote your post (although I almost never down vote posts for other reasons than spamming, insults, completely off-topic posts or other clear netiquette violations). I'll refrain from doing it here in consideration of the fact that you are new here.