here is what I have so far: while( ) { chomp; $count++; # skip header next unless $count; my $row; @$row = split( /,/, $_ ); push @$sheet, $row; } foreach my $row ( sort { $a->[0] cmp $b->[0] || $a->[44] cmp $b->[44] } @$sheet ) { print OUT join( ',', @$row ), "\n"; }