It sounds like you are asking us to do a large part of your project for you, which is not really what this site is here for. Yes, perl will allow you to create a sort routine (must return 0,-1, or 1) and to then use that routine to
sort an array. There are also good methods for formatting your output to look the way you want it to. But to give you a complete answer I think I would have to type in most of the first half of the Camel book.