use strict; use warnings; use B; package Foo; sub thing {} my $ref1 = \&package1::sub1; my $ref2 = \&thing; package Bar; for ($ref1, $ref2) { print B::svref_2object($_)->STASH->NAME, "\n"; print B::svref_2object($_)->GV->STASH->NAME, "\n"; } # Output: # main # package1 # Foo # Foo