#! perl -slw use strict; $|=1; my $tree = { top => { inetUser => {}, person => { organizationalPerson => { managedPerson => { personnel => {}, }, }, }, application => { managedApplication => {}, }, }, }; sub explore; sub explore { my( $tree, $leaf ) = @_; for my $node ( keys %$tree ){ return $node if $node eq $leaf; next unless keys %{ $tree->{ $node } }; my @found = explore $tree->{ $node }, $leaf; return ( $node, @found ) if @found; } return; } printf "Looking for %-20s: %s\n", $_, join ' -> ', explore $tree, $_ for qw[ fred inetUser managedApplication personnel ]; __END__ P:\test>test Looking for fred : Looking for inetUser : top -> inetUser Looking for managedApplication : top -> application -> managedApplication Looking for personnel : top -> person -> organizationalPerson -> managedPerson -> personnel