use warnings; use strict; use Data::Dumper; my %hash = (); my @array = (1,2,3}; my $href = \%hash; for ( @array ) { $href->{$_} = {}; $href = $href->{$_}; } print Dumper (\%hash); #'1' => { # '2' => { # '3' => {} # } # }