use DBI; DBI connection stuff here... # no error handling code included in this sample $sth = $dbh->prepare(qq|SELECT row_id FROM test WHERE exe='N'|); $rows = $sth->execute(); $sth2 = $dhb->prepare(qq|UPDATE test SET exe = 'Y' WHERE row_id = ?|); while ($row_id = $sth->fetchrow_array()) { # now execute the 2nd statement replacing the # placeholder with the variable $row_id $sth2->execute($row_id); } $sth->finish(); $sth2->finish(); $dbh->disconnect();