my $dbh = DBI->connect("DBI:mysqlPP:host=localhost;database=foo",'bar','baz',{ AutoCommit => 1, RaiseError => 1, PrintErrors=>1}) or die "Cannot connect"; ... 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->bind($color); $sth->execute() or die $dbh->errstr; }