in reply to Why no stay shared warning?

Why is get defined inside of up?

Anyways, in addition to the other suggestions that you have been offered, I tend to use lazy memoization as follows:

{ my $foo; sub up { unless (defined)($foo)) { $foo = 1; } $foo++; } sub get { $foo; } }
And now the initialization happens when the subroutine is called. (This is a very handy pattern when the variable takes some work to create - eg for a database handle - and you may or may not need it.)