my $sql = 'select page_title, page_touched from proadvpag where page_namespace = 0 and page_is_redirect = 0 and page_touched < NOW() - INTERVAL 100000000 SECOND'; my $sth = $dbh->prepare($sql); $sth->execute($then); while (my $row = $select->fetchrow_hashref) { # all rows returned are ones you want to send an # email about }