あたまがわるい。

#!/usr/bin/perl

use strict;
use warnings;
use Text::CSV_XS;

my $file = shift or die;

open my $fh, '<:encoding(cp932)', $file or die $!;
my $csv = Text::CSV_XS->new({binary => 1});
my $out = [];
my $j = 0;
while (my $row = $csv->getline($fh)) {
    for (my $i = 0; $i <= $#{$row} ; $i++) {
        $out->[$i]->[$j] = $row->[$i];
    }
    $j++;
}
close $fh;
my $out_csv = Text::CSV_XS->new({binary => 1, always_quote => 1});
for my $line (@{$out}) {
    $out_csv->combine(@$line);
    print $out_csv->string, "\n";
}