in reply to Global Variables

It's not a good idea to declare a variable inside an if-block when you want to use it in the surrunding block - what happens if the if-condition is false and it's not executed?

The solution is to declare the variable in an outer scope:

my $new_variable; if ($condition){ # initialize $new_variable here } # far down below, you can still use $new_variable.