my $dbh = DBI->connect("DBI:mysqlPP:host=localhost;database=foo",'bar','baz',{ AutoCommit => 1, RaiseError => 1}); ... some stuff... foreach my $color (@color){ # trim whitespace $color =~ s/^\s+|\s+$//gm; # see if the color already exists in the color table. my $rowCheckQuery = qq{SELECT color_id FROM color WHERE color=?}; my $sth = $dbh->prepare($rowCheckQuery); $sth->execute($color); }