my $results = $dbh->selectall_arrayref("SELECT ID from table", { Slice => {} }); my %ids = map { $_->{ID} => '1' } @$results; for ( 1 .. 10000 ) { next if $ids{$_}; #do site stuff here or push to an array to use later print "$_\n"; }