my @a = qw[ one two three ]; my $x = 1; $hash = {}, $hash->{ $_ } = $x, $x = $hash for reverse @a; print Dumper $hash; $VAR1 = { 'one' => { 'two' => { 'three' => 1 } } };