The scoping of local only actually undefines a variable , you could use my to make it scope specific in the code ,so that it is global like my $stout ,local actually is not the one that is to be used in this part of the code for what you wanted to do actually