use Sub::Util qw/subname/; sub foo {} my $test = \&foo; print subname($test); # prints "main::foo"