use Text::CSV; my $csv = Text::CSV->new; ... $csv->print(\*STDOUT, $sth->{NAME}); while (my $row = $sth->fetchrow_arrayref) { $csv->say(\*STDOUT, $row); }