if you have enough memory you can substr 5 chars at a time into a hash and ++ the key, then inc the index of the substr until you have hashed the entire number. then sort by the largest value of the hash. This will take a lot of memory though so you would need a beefy box (or use
Tie::Hash to save memory). The second advantage to this is you can see the rank of all 5 char sequences afterproccessing the file 1 time.
-Waswas