There appears to be something missing from that code. $func and $name have no means of being populated, and even if they were, nothing gets done with $stub after it's been created. If you change the first line to my ($func, $name) = @_;, then I believe you can change thing_to_profile(@args) to profile(\&thing_to_profile, "thing_to_profile")->(@args) and the code will work as expected.
Jeff japhy Pinyan,
P.L., P.M., P.O.D, X.S.:
Perl,
regex,
and perlhacker How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart