$sth->execute; open (OUTFILE, "> file.txt") or die "Cant open dat file : $!"; while (@row = $sth->fetchrow_array) { $_ =~ s/\s/\|/g; $_ =~ s/(.*)/|$1|/; print OUTFILE "@row\n"; } close OUTFILE;