in reply to how do i create a global var conditionally?

You're trying to dynamically generate code.

perl -e'... if ($xyz) { print "my \$globalbar;\n"; } ...' | perl

yuck.


which obviously doesn't work as $globalvar will only be local to the it's subroutine.

No, its scope is limited to block (curlies) it's in.