I'm guessing the long exit time is because perl must free all the memory it used up in the processing of all this data. Perhaps you could either make your algorithem more memory efficient, or use a tied hash? Not sure what that would do to your performance though.