while(@parts) { # walk through each part of the path my $part=shift(@parts); my $elm=$tmphash->{$part}; # Does the part exists in the hash-tree? if(defined($elm)) { # Is this the last part of the path? if(!@parts) { # Yes, the folder is in the database! $found=1; #leave loop last; } # Not the last part of the path else { # if possible # Go one level further if(ref($elm) eq 'HASH') { $tmphash=$elm; } else { last; } } } else { # The path is not in the database last; } }