diffrent recommendations:
1.- only open the file if you want to read it, then you won't have to close the handle if you didn't need to open it in the first place.
2.- if you want to keep it in the text files and parse them every time, consider
File::Slurp, which is the fastest way to slurp i know.
3.- if you want to have it really fast, have a look at the first chapter of Programming Pearls by Jon Bentley. The Basic idea is to use a bitstring(initialized with zeroes), and toggle the bits to 1 (plain old binary OR)which represents the telefone number. As Telefone Numbers are unique, and you don't have any data associated with it, its an valid approach, to check for the existence of a number. If you want you can create that bistring once, and only read it in afterwards (you could use
Storable, or plain spewing using
File::Slurp). This should drastically reduce your memory consumption and speed should be lightning fast.
Update: using
Bit::Vector::Array would probably be the simplest way to achieve the bitstring (simply use the telefone number as an index). Like that you would only need one OP (no searching needed, just check that index of the bit vector whether its 1 or 0) for an lookup. Initialization of the bit vector would be just as easy, simply toggle the bits with the correct index to 1.
Hope this gives you some ideas.
Cheers
Roland