in reply to Variable scoping outside subs

You exit before line 6 is reached - it is executed at runtime. You will get the behavior I think you expect by rearranging,

use strict; { my $var = 1; sub test { print "var was '$var'\n"; $var++; print "var is now '$var'\n"; } } test(); exit 0;
The extra braces are just to limit the scope of $var further. Search closure here for much more.

After Compline,
Zaxo

the monastery: (36)