in reply to detecting an undefined variable

Using an non-existant variable is a fatal compilation error under strict (which one should always use). This smells of using a variable as a variable name, which is generally considered a bad practice... why would you want to do this, what do you need this for?

Normally, the solution to this kind of thing would be to use a hash instead, where the defined and exists checks apply (with the differences explained in their documentation).

Enough rope to shoot yourself in the foot: For package variables, one can use if ( defined $::{'VARNAME'} ) ... (Update: although this checks for any symbol with that name, including arrays, hashes, subs, etc. - one could use peek_our from PadWalker instead, similar to the following example), and for lexical variables use PadWalker qw/peek_my/; if ( defined peek_my(0)->{'$VARNAME'} ) .... But don't do this.

Update: Minor edits.