If you have a failure case, don't return undef; - just return;. That will DWIM for both scalar and list contexts. (If you don't know contexts, don't worry - it will behave correctly.)
Then, if you want to check to see if it's got anything, just if (%hash) { ... }.
The Perfect is the Enemy of the Good.
Comment on Re: How to have a subroutine return an undefined hash