Yes, it is possible. Simply declare $key outside the while loop instead of inside it. See Coping with Scoping.
Of course you'll only see the value from the last time $key is set but it's not immediately clear from your post if that's a problem for you.
In reply to Re: preserving hash value outside the loop
by hippo
in thread preserving hash value outside the loop
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |