in reply to Summarizing Mail Activity (Long Tail Problem)

One data structure that can efficiently keep the top n of a large set of cases is a heap, specifically a minimum heap. You insert cases into the heap until is reaches size n, then after each insertion delete the minimum. After all cases have been processed, the heap contains the top n, which can be extracted lowest to highest. The heap never grows larger than n+1

There are a few modules on CPAN that implement heaps. If cou need persistence (I'm not sure if your problem requires that), Storable will probably be able to add it.

Anno