#!/usr/bin/perl -w use strict; #always use strict my %sortKey; open (INFILE, "filename"); #open the file while { #iterate through the file line by line my @tmp = split /,/; #split the file on the comma #for the sake of the example we will say that the first #element of the file is what you want to sort on #so we will make it the key to our hash $sortKey{$tmp[0]}=$_; } open (OUTFILE ">outfile"); #this will take the keys, shove them in an array, sort #them and set $key equal to the current sorted key foreach my $key (sort(keys(%sortKey))) { print OUTFILE " %sortKey{$key}; }