my $hash; $hash = { $_ => $hash } for reverse @array; #### my $ref = \$hash; $ref = \$$ref->{$_} for @b;