use B qw( svref_2object ); sub get_package { my ($obj, $method_name) = @_; my $method_ref = $obj->can($method_name) or return undef; return svref_2object($method_ref)->FILE; }