#new.pl my %total=map{$_,0}(qw(weekly daily blast custom)); my $updateSql=qq[UPDATE shawnTest set sent='Y' WHERE emailId=?]; my $update=$dbh->prepare($updateSql); while(@emails = $sth->fetchrow_array()) { open (OUT, ">>newEmail.txt"); print OUT "To: $emails[3]\nFrom: $emails[4]\nSubject:$emails[1]\n\n$emails[2]\n"; close OUT; $update->execute($emails[0]); $total{$emails[5]}++; }