my (%withlex, %withglobal); for (1 .. 10) { my $ref = sub { return $_ }; $withglobal{$ref} = $ref; } for my $i (1 .. 10) { my $ref = sub { return $i }; $withlex{$ref} = $ref; } print "Using lex num of subs is " . (keys %withlex) . "\n"; print "Using global num of subs is " . (keys %withglobal) . "\n"; #### Using lex num of subs is 10 Using global num of subs is 1