my $sth = $dbh->prepare( 'SELECT count(*) FROM num_table WHERE num = ?' ); foreach my $n ( @num_from_doc ) { $sth->execute( $n ); my ($exists) = $sth->fetchrow_array; my $not = $exists ? '' : ' not'; print "Number $n is$not in the database.\n"; }