#!/usr/bin/perl -w use strict; use warnings; use Text::CSV_XS; open(my $FILE1, '<', "inputfile.csv") or die "cannot open file1 $!\n"; open(my $FILE2, '>', "outputfile.csv") or die "cannot open file2 $!\n"; my $csv =Text::CSV_XS-> new({binary=> 1, eol=> $/, sep_char=> "\t", always_quote=>1}); my @tfields; while(my $row=$csv->getline($FILE1)) { my @fields=@$row; for my $y (0..(@fields-1)) { for my $x (0..@{$fields[$y]}-1) { $tfields[$x][$y] = $fields[$y][$x]; $csv->print($FILE2,\@tfields); } } }