$ perl -e' use feature qw( say ); $x = 2; say 0+\$x; say $x; sub { local $x = 3; say 0+\$x; say $x; say $_[0]; }->( $x ); say 0+\$x; say $x; ' 94300947464040 Address of pre-local $x 2 Value of pre-local $x 94300947268840 Address of post-local $x 3 Value of post-local $x 2 Value of pre-local $x 94300947464040 $x is restored 2 Value of pre-local $x