in reply to conditional definition of variables

Script2:
#my $var = "xxx\n"; my $var="zzz\n" unless defined($var); print $var;
Name "main::var" used only once: possible typo at unlesstest.pl line 2 +. zzz

That happens because before doing the assignment, the right-hand-side of the statement must be resolved. So, a global variable $var is created, and then masked immediately by a lexical variable $var. These variables are not related, and the warning is about the global one, which isn't accessible any more, since it is masked immediately by the my variable.