my $hash{key} = ...; # is illegal local $hash{$key} = ...; # is legal #on the other hand my $x = 1; { my $x = 2; # is legal, a new variable was created, outer $x is not visible } #while my $x = 1; { local $x = 2; # is illegal. Can't localize a lexical variable