$ cat pivot.pl #!/pro/bin/perl use strict; use warnings; use Text::CSV_XS; use Spreadsheet::Read; my $ss = ReadData (shift)->[1]; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, eol => "\r\n" }); $csv->print (*STDOUT, [@{$ss->{cell}[$_]}[1..$ss->{maxrow}]]) for 1 .. $ss->{maxcol}; $ cat test.csv a,b,c,d,e,f 1,2,3,4,5,6 2,3,4,5,6,7 3,4,5,6,7,8 4,5,6,7,8,9 $ perl pivot.pl test.csv a,1,2,3,4 b,2,3,4,5 c,3,4,5,6 d,4,5,6,7 e,5,6,7,8 f,6,7,8,9 $