use strict; use warnings; use DBI; my $dbh = DBI->connect("DBI:mysql:foo;mysql_read_default_file=~/.my.cnf", undef, undef, { AutoCommit => 1, RaiseError => 1, } ); my @color = qw( red blue green puce majenta lavender lake teal ); my $sth_color_exists = $dbh->prepare("SELECT 1 FROM color WHERE color = ?"); # uncomment to get lots of info about what's going on. # DBI->trace(2); for my $color ( @color ) { $color =~ s/^\s+|\s+$//g; my $rv = $sth_color_exists->execute($color); printf(qq{There %s %d row%s found for color = "%s"\n}, $rv == 1 ? "was" : "were", $rv, $rv == 1 ? "" : "s", $color ); } $sth_color_exists->finish();