in reply to sub getting reference to itself : generic way

my $coderef = do { my $selfref; $selfref = sub { # use $selfref here for recursion }; };
Note that this will cause a memory leak; it's a high-tech variant of $a = \$a.

Dave.