in reply to Getting the name of sub from sub reference

Replace

$msg .= "cannot call $q\n";

with

$msg .= "cannot call @{[eval {&$q}, $@ =~ /^[^&]+(\S+)/]}\n";

and the output becomes

hello from ABC(hhhhhh) cannot call &main::def

You can use

@{[eval {&$q}, $@ =~ /^[^&]+(\S+)/]}

in any double-quoted string for whatever reporting purposes you want.

Thanks to BrowserUk for the eval bit (above).

-- Ken