in reply to Modifying value of $1 clobbers $2, $3 etc?

You give the answer yourself:
The scope of $<digit> extends to the end of the enclosing BLOCK or eval string, or to the next successful pattern match, whichever comes first.
Line 7 of your script is a successful pattern match (a substitution is also a pattern match), so the $<digit> vars go out of scope (well, they are reset to undef by the new pattern match).

Update: removed inaccurate or even plain wrong stuff.

CU
Robartes-

  • Comment on Re: Modifying value of $1 clobbers $2, $3 etc?