use Carp; my $i = 0; sub foo { sub { local *__ANON__ = "local_subref_" . $i++; carp "blokhead"; }; } foo()->() for 1 .. 3; __OUTPUT__ $ perl -d:DProf test.pl blokhead at test.pl line 7 main::local_subref_0() called at test.pl line 12 blokhead at test.pl line 7 main::local_subref_1() called at test.pl line 12 blokhead at test.pl line 7 main::local_subref_2() called at test.pl line 12 blokhead at test.pl line 7 main::local_subref_3() called at test.pl line 12 $ dprofpp tmon.out Total Elapsed Time = 0.079705 Seconds User+System Time = 0.049705 Seconds Exclusive Times %Time ExclSec CumulS #Calls sec/call Csec/c Name ... 0.00 - 0.020 3 - 0.0066 main::__ANON__ ...