my $file = "path/to/client.csv"; # make sure this location is writable! open F, ">$file" or die "Couldn't create $file: $!\n"; print F "CLIENT NAME,DC,FF,OTHERS\n"; while(@row = $dbh->dbnextrow()) { print F join(/,/, @row), "\n"; } close F;