This is the nature of the execution flow of perl -
my @r hasn't been 'executed' yet, so you'll want something along the lines of a
BEGIN block if you want it to be initialized and have it
after the subroutine call e.g
foo();
BEGIN {
my $str = 'a string';
sub foo { print "\$str is $str\n" }
}
__output__
$str is a string