{ my $x = 1; sub foo { # commenting this out causes the print to see an undef value $x; sub { print "x=$x\n" }->(); } } foo();