in reply to unexpected: inside sub($1,$2) if do // then arguments will be changed

perlvar says "read-only and dynamically scoped"

They are. mysub does indeed back them up on entry and restore them on exit.

$ perl -E' sub f { say $1; "b"=~/(b)/; say $1; } "a"=~/(a)/; say $1; f(); say $1; ' a a b a

The problem is that $_[0] and $_[1] are aliased to $1 and $2, so changing $1 and $2 changes $_[0] and $_[1].

$ perl -E' sub f { say $_[0]; "b"=~/(b)/; say $_[0]; } "a"=~/(a)/; f($1); ' a b

Three solutions: