use IO::Handle qw( ); ... my $out_fn = 'C:\\Program Files\\cron\\Cruise Ships\\ship_data.csv'; open(OUTFILE, '>', $out_fn) or die("Unable to create output file \"$out_fn\": $!\n"); ... print (OUTFILE $input); ... OUTFILE->print ( join(',', @$row), "\n");