Consider raising an exception (with die) when the error happens. Using the return value of a sub for both data and error signalling tends to always have this problem: using exceptions makes error conditions out-of-band and lets you treat the error when it's most convenient for you.
I was about to give an example, but then I realized I don't understand what myfunction() is doing and who opens FILEHANDLE.