my $p= \%hash; my $last= pop @splittedline; foreach @splittedline { $p->{$_}={} if (not exists $p->{$_}); $p= $p->{$_}; } $p->{$last}= 1;