#!/usr/bin/perl -w use strict; use Text::CSV_XS; my @data = ( ["Hello,\nworld" ], ["One\nTwo\nThree"], ); my $csv = Text::CSV_XS->new({binary => 1}); open CSV, "> example.csv" or die "Couldn't open file. $!\n"; binmode CSV; for my $aref (@data) { $csv->combine(@$aref); print CSV $csv->string(), "\r\n"; }