my $csv = Text::CSV->new({ binary => 1, sep_char => "\t", always_quote => 1, }) or do { print STDERR "Cannot initialize CSV: ", Text::CSV->error_diag, "\n"; exit 1; }; LINE: while (my $row = $csv->getline(\*STDIN)) { s/\n/$replace/g foreach(@$row); unless($csv->combine(@$row)) { print STDERR "Error converting record $. for output: ", $csv->error_input, "\n"; next LINE; } print $csv->string, "\n"; } $csv->eof or $csv->error_diag;