my %hash = ( "Abe" => { "lastname" => "Lincoln", "friends" => { "George" => { "lastname" => "Washington", "wife" => "Martha" } "James" => { "lastname" => "Madison", "wife" => "Dolly" } }, }, "Franklin" => { "lastname" => "Roosevelt", "wife" => "Eleanor" } ) #### #!/your/perl/here use strict; use warnings; use Data::Dumper; sub update_hash { my ($h, $value, @keys) = @_; for my $key (@keys[0..$#keys-1]) { $h = $h->{$key}; } $h->{$keys[-1]} = $value; } # build up a hash from scratch my %hash; update_hash(\%hash, {}, 'one'); update_hash(\%hash, {}, 'one','two'); update_hash(\%hash, 123, 'one','two','three'); # don't have to start at the top update_hash($hash{one}{two},129,'nine'); update_hash($hash{one}{two},{},'zero'); update_hash($hash{one}{two},1208,'zero','eight'); print Dumper(\%hash); __OUTPUT__ $VAR1 = { 'one' => { 'two' => { 'three' => 123, 'zero' => { 'eight' => 1208 }, 'nine' => 129 } } };