# Assumes DBI RaiseError is set ... my $sth = $dbh->prepare ("SELECT ID from $tbl where ID=?"); for my $id (1..10_000){ $sth->execute ($id); next if $sth->fetchrow_arrayref; # This ID ($id) was absent # Generate web page here... }