in reply to efficiency of exists()

Looking up hash-keys is an O(1) operation, so it should be as fast for a hash with 10 or with 1000 or with a 1000000 elements. That's the beauty of hashes. Perl does not have to "walk" the hash, the hashing function will directly "jump" to the right location and see if the key exists.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James