in reply to Anonymous coderefs

It's cheating, but Sub::Recursive kind of does that with very little effort for you.

use Sub::Recursive; #my $foo = sub { ... }; my $foo = recursive { ... };
and inside the block $REC is a reference to the subroutine.

ihb

See perltoc if you don't know which perldoc to read!