$sth = $dbh->prepare("select COLUMN_1 from table where COLUMN_2 < 2500"); $sth->execute(); while (my ($column_1_value) = $sth->fetchrow_array()) { # do some processing on the column 1 value here } #### $sth = $dbh->prepare("select COLUMN_1 from table where COLUMN_2 between ? and ?"); for ($i = 0; $i < 2500; $i += 100) { $sth->execute($i, $i + 100); while (my ($column_1_value) = $sth->fetchrow_array()) { # do some processing on the column 1 value here } }