$sth_detections = $dbh->prepare("$QUERY2") || die $DBI::errstr; for ... my $city = $city[$i]; my $station = $station[$i]; $sth_detections->bind_param(":city", $city); $sth_detections->bind_param(":station", $station); $sth_detections->execute; @row = $sth_detections->fetchrow;