in reply to Missing something with regards to references

Use List::Util::reduce. You have a serious problem if you use the approach you selected. If you have already added "a", "b" = 1, what happens when you say "a", "b", "c" = 2? Using your existing code you will immediately die on symbolic references. Better, solve the problem by putting the child node references into a separate key and store your values in another.

use List::Util 'reduce'; use Carp 'carp'; # a.tree => b.tree => c.tree => ... z.value sub put_element { 'HASH' eq ref( my $root = shift() ) or carp "put_element( \ %..., [ KEY ], $val ) must be a hash r +eference"; 'ARRAY' eq ref( my $keys = shift() ) or carp "put_element( \ %..., [ KEY ], $val ) must be given an + array reference"; my $value = shift; my $leaf = reduce { $a->{$b}{'tree'} ||= {} } $root, @{$keys}[ 0 . +. $#$keys - 1 ]; $leaf->{$keys->[-1]}{'value'} = $value; }