sub get_key { my $key; unless ($done) { ($key, my $value) = each %$hash_ref or # yes, $value is out of scope $done = 1; } defined $key ? $key : ""; }