Thanks to you all for replying and giving me some thoughts. Will check out the link of the youtube video when I get more time.
Here is more of the context: the subroutines (in the form of strings) was sent to my server on the fly for execution by a function under my control. I wish I can go and change the source of the subroutines to add an explicit "return undef" (the function is executed on my side in scalar context, so it's ok) but I can't. I am thinking of modifying the incoming subroutines, if it doesn't have a "return undef" before the ending of the subroutine, I will add one. But it's not elegant.