in reply to testing defined($x) && length($x)
Sure:
if (has_length($x)) { ... } [download]
Implementation of has_length left to the reader.