in reply to Setting a multi-dimensional hash value

Recursively:

use strict; use warnings; use Data::Dumper; sub set_hash { my $href = shift; my $val = shift; my $key = shift; if( @_ ) { $href->{$key} = {} if not exists $href->{$key}; set_hash( $href->{$key}, $val, @_ ); } else { $href->{$key} = $val; } } my %h; set_hash(\%h, 42, 'a', 'b', 'c'); set_hash(\%h, 69, 'x', 'y', 'z', 'aa' ); print Dumper(\%h);