in reply to useless use of sort???

You don't appear to be using the @sortlist array; all your output seems to be already done at that point. What did you want to happen to the sorted data?

It looks like perhaps you want to be saving things into a @cpout array instead of writing to CPOUT, and then sorting that and writing it after the <FILE> loop, but then again, maybe not.