while (1) { $sth = $dbh->prepare(qq{select * from customers where mark=0}); $sth->execute() or die "$DBI::errstr\n"; while ($sth->fetch) { my $content = construct_the_customers_template(); send_customer_mail($coutnet); mark_the_flag_in_msgdb(); # set the mark field to 1 ,represent has sent! } }