my %hash = (foo => {}); my $ref = \%hash; for (0 .. shift @ARGV ) { $ref = $ref->{foo}; $ref->{foo} = {}; }