in reply to Unusual Closure Behaviour
The word that I keep seeing left out of these replies is 'precedence'. It looks to me like there is confusion between
my ($x if undef);
(my $x) if undef;
It looks to me like you are expecting the latter and getting the former. I suspect 'if' is being evaluated as an operator, so it gets a higher precedence than the 'my' function, and confusion results.
Or I could be completely wrong.