... # now sort my @sorted_dat = sort tableSorter @csvdata; @csvdata = (); ## Discard the unsorted data ## csvify and output the sorted data one line at a time ## so avoiding two more in-memory copies # arrange the sorted array into cav format print $outfile join( ", ", @{$_} ), "\n" for @sorted_data; # close the output file close($outfile);