in reply to Something like c++'s static?

Another approach in newer perls gives something that looks very C-like in use. Make foo an lvalue accessor which takes no arguments:

BEGIN { my $foo = "default"; sub foo () : lvalue { $foo } } print foo, $/; foo = "special"; print foo,$/;

The BEGIN block is only needed to get the "default" value in early (completely unneeded in this simple case). In a module, you can leave 'foo' off the @EXPORT_OK list so it's perlishly private to the module package.

For thread safety, you'd want the 'locked' attribute, besides 'lvalue'.

Update: Added clarification on the BEGIN block, and an unwise adverb.

After Compline,
Zaxo