$sql = "INSERT INTO theTable (response, respondent) VALUES (?,?)"; $sth = $dbh->prepare($sql) or die("Could not prepare!" . $dbh->errstr); $i = 1; for $respondent (1 .. 20000) { for $r (0 .. 600) { $response = $i + ($r * 5); $sth->execute($response, $respondent) or die("Could not execute!" . $dbh->errstr); } if ($respondent % 2) { $response = 9999; $sth->execute($response, $respondent) or die("Could not execute!" . $dbh->errstr); } else { $response = 6666; $sth->execute($response, $respondent) or die("Could not execute!" . $dbh->errstr); } if ($i < 5) {$i++;} else {$i = 1;} }