open my $fh, q{>}, $datafile or die qq{cant open $datafile to write: $!\n}; my $header_rec = join(",", @{$read_sth->{NAME}}); # print the header to the filehandle print $fh $header_rec . "\n"; while (@data = $read_sth->fetchrow_array) { # lets see what we have die @data; my @data = EQ_Misc::arr_replace_undef("", @data); my $csv_record = join(",", @data); # you're writing the array _and_ the record (and a dot)? #print $fh "@data $csv_record .\n"; # did you mean? print $fh qq{$csv_record\n}; } #close $datafile; close $fh;