foo(); BEGIN { my $str = 'a string'; sub foo { print "\$str is $str\n" } } __output__ $str is a string