in reply to Re: Conditional initialization of lexical (my) variables
in thread Conditional initialization of lexical (my) variables

So when the next line assigns to 'my_var' - the assignment is done to a global variable.

That's not what's happening. It is indeed assigning to the lexical var.

Running my pushes a directive on the stack that clears the lexical var on scope exit. This is what's being skipped in the OP's code.