my $step = \%hash; while ( my $part = shift $pathparts ) { $step->{$part} ||= {}; $step = $step->{$part}; }