$csv->print (*STDOUT, [@{$sth->{NAME_lc}}]); #### my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); $csv->print (*STDOUT, [@{$_read_sth->{NAME}}]); while (my $row = $_read_sth->fetchall_arrayref) { # If you need to add other headers ... $csv->print (*STDOUT, [qw( some different header )]) if $needed; # print the data fetched $csv->print (*STDOUT, $row); }