use Data::Dumper; $VAR1 = { 'misc' => {}, 'docs' => { 'howtos' => { 'email' => { 'index.html' => { 'date' => '21-1-2004', 'size' => '691' } }, 'ftp' => {}, 'ssh' => {} } } }; $fs = "/docs/howtos/email/"; $v = $VAR1; # this is the actual processing map { $v = $v->{$_} } grep { length > 0 } split m./., $fs ; print Dumper $v;