in reply to Reference to an anon sub from within.

Replace "sub {" with "do { my $sub; $sub = sub {" and add a "}" on the end. Then inside of the sub, $sub will be a reference to the sub:

do { my $sub; $sub = sub { print "I am $sub\n"; } }->();

- tye