in reply to sub returning undef

Which built-in functions return arrays but return undef on error?

I both would not recommend that style, and strongly suspect that you're misunderstanding something basic about the behaviour of those functions.