in reply to How come undef eq '' ??

just replace
if( $tmp and ( $tmp eq "" ) )
with
if( defined($tmp) and ( $tmp eq "" ) )