in reply to defined vs null string

I think that the source of your confusion may be that if (defined $y) { is not testing whether the variable $y is defined.

It is testing whether the variable $y is currently set to a defined value.

In C, the is the concept of "defining variables" (which somewhat conflates with the concept of "declaring variables"), and may be the source of the confusion here, in that the declaration my $y; is also sometimes referred to as "defining $y".

But that has litte or nothing to do with the use of the built-in defined function, which tests whether the value held by the variable is a defined value, not whether the variable itself has been declared (or defined :).

In retrospect, defined might have been better named notUndef()


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.