in reply to variable has value but then become empty
Also consider the implications of the following bit of code, which compiles and runs without errors or warnings:
Whose output is: foo baruse strict; use warnings; my $foo = "bar "; { my $foo = "foo "; print $foo; } print $foo;
The definition of $foo which exists within the anonymous block conceals, without warning, the variable of the same name that exists outside the block. Two entirely distinct values are maintained, each referred-to at different times and in different scopes by the same variable name. Within the block, the value "bar " cannot be reached, and there is nothing to alert you to the probably-unintentional conflict.
This is not “incorrect” behavior. It is, in fact, by design, although it might be slightly different from other languages you have used (and whose error, warning, and informational messages you might have come to rely upon). This it just might be yet-another reason why “global variables are not a particularly good idea.”