in reply to sorting CSV files

DBD::CSV might do the job. It lets you run SQL queries over the data.