http://www.perlmonks.org?node_id=489881

blazar has asked for the wisdom of the Perl Monks concerning the following question:

I would like to premise that I'm completely ignorant of current perls' internals. However in informal discussions people with much more experience and knowledge about it told me that the lexical pad is not much different from a common package. Now I wonder if it has a code slot too, or if one could easily be added if not, so as to allow for lexically scoped named subs too:
my sub foo { # ... }
Now, I'm sure some one will mention that I can do
my $foo = sub { ... };
instead. And yes, of course I knew, but even if we don't feel an extreme need for lexically scoped named subs it wouldn't be too bad to have them either. Maybe they may go into 5.10, couldn't they?

Thus we may have something like this:

sub invert { my ($n, $p)=@_; # Trusting $p to be a prime... my sub expp { my ($n, $m)=@_; return 1 unless $m; ($m%2 ? $n : 1) * expp($n, $m >> 1)**2 % $p; } expp($n, $p-2); }
This is of course an oversimplified and probably not extremely appropriate example, but I hope it gives an idea...