my @tmp = qw( a b c d ); my $hash = [0]; # not really a hash foreach my $key ( reverse @tmp ) { $hash = { $key => $hash }; } use Data::Dumper; print Dumper( $hash );