while (){ # where NEWDATA points to a file with the comma delimited data $currLine = $_; # current, comma-delimited line chomp $currLine; @formatDataArray = split(/,/,$currLine); #split at comma push (@newArray, $formatDataArray[0]); # push first column into newArray # print OUT "@newArray\n"; } foreach my $item(@newArray){ # get unique array elements $seen{$item}++; } # numerical sort on keys and add to array @uniq = sort {$seen{$a} <=> $seen{$b} } keys %seen; # print to see if things look right foreach my $element(@uniq){ print OUT "$element\n"; }