Interesting Perl behavior

#!/usr/bin/perl -w
my $val = 0 if (0);$val = 1 unless defined($val); print "Val:$val\n";
$val = 2; } foo(); foo(); The output of this call gives: Val: 1 Val: 2 Although the expected result would seem to be: Val: 1 Val: 1 Using Google, I found the following nugget from perlsyn: 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. http://perldoc.perl.org/perlsyn.html#Statement-Modifiers