#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new({ binary => 1, allow_whitespace => 1, allow_loose_quotes => 1, }) or die Text::CSV->error_diag (); open my $csvfile, '<', 'in.csv' or die "cannot open in.csv for reading: $!"; open my $fout, '>', 'out.txt' or die "cannot open out.txt for writting: $!"; my $line_no = 0; while (my $record = $csv->getline($csvfile)) { $line_no++; my $value = "$record->[9], $record->[7], $record->[8] $record->[10]"; printf {$fout} "[%06d] %s\n", $line_no, $value; } __END__