in reply to Re^2: immutable pos() inside regex
in thread immutable pos() inside regex

The following piece of code clearly demos two things:
  1. $_ is $str, base on the facts that:
    1. addresses are the same;
    2. $str has been changed even outside the regexp.
  2. However it also clearly demos that regexp only copies the target string once at the beginning, when you enter the regexp engine, as you can see $1 steps through the stream of "a string", not "abc". regexp engine uses its own copy of the target entity, which again, makes sense, whoever wrote regexp need to make the regexp itself robust. They simply disallow you to alter the status and properties of the regexp engine in the way, which you thought you could, but they thought dangerous.
$\ = "\n"; $, = ","; $str = "a string"; print \$str; $str =~ m/(?:(.)(?{print "address of \$_ is ".\$_.";";print '$_ = '.$_ +.";";print "\$str = ".$str.";";print "\$1 = $1\n";$_="abc"}))+/; print $str;