in reply to sub scope question

That's because defining named subroutines is done at compile time. Here's an illustrative example:

sub a { sub x { print "I came from a\n"; } } sub b { sub x { print "I came from b\n"; } } x(); a(); x(); b(); x();

This generates:

I came from b I came from b I came from b

To do things your way you can localize the subroutine name, i.e.:

sub a { local(*x) = sub { "from a" }; doit(); } sub b { local(*x) = sub { "from b" }; doit(); } sub doit { print "I came ", x(), "\n"; }