Do not use
defined on hashes or arrays. It does not mean what you apparently think it means. It means something entirely useless to most Perl programmers: "does this aggregate variable have allocated memory for its contents". So, if it's defined, it has non-empty content, but the converse is not true.
-- Randal L. Schwartz, Perl hacker