in reply to Lexical scope variable is not undef'ed

my $var = '' if 0 creates a static variable (ie one that retains its value through successive iterations of your loop) in the version of perl you are currently using. Generally, the action of the construct you've used is undefined and, as such, shouldn't be used.

In short...

DON'T DO IT

Update: Here's what perlsyn has to say about it:

NOTE: The behaviour of a "my" statement modified with a statement modifier conditional or loop construct (e.g. "my $x if ...") is undefined. The value of the "my" variable may be "undef", any previously assigned value, or possibly anything else. Don't rely on it. Future versions of perl might do something different from the version of perl you try it out on. Here be dragons.