in reply to Re^4: Local $$_?
in thread Local $$_?

All you really needed was

print "local \$$_ = \$$_;\n" for @listofvarnames;
then you copy/paste
local $blah = $blah; ...

Although it is not a perfect solution - it seems to be working.

The use of global variables is red flag. Your statement that "it seems to be working" also indicates that it doesn't come with a test suite, another red flag. I think now is a time to consider/plan to refactor this program.