in reply to I can crash perl

Maybe you should stop copying so much data around, you're storing multiple copies and doing far too much work -- IMHO :)

If you stored your info in a hash then you could just sort a list of the keys into the order you require. see perldata and the data structures cookbook perldsc for some guidance.