# As long as we have multiple keys, access the next subhash while (@keys > 1) { my $key = shift @keylist; $hashref = $hashref->{$key}; }