#!/usr/bin/perl -w use strict; # Open the source file, take each record and split it into ip, range, # and country fields and push a ref to the anon array into our recordset my @records; open IPS, "; close IPS; # Perform the sort on the country field (element 2 of our anon array) my @sorted = sort { $a->[2] cmp $b->[2] } @records; # Join all the sorted pieces back together and write it to file. open SORTED, ">sorted"; print SORTED join(",", @$_) for @sorted; close SORTED;