$sth=$dbh->prepare($sql); $sth->execute; while(($var)=$sth->fetchrow_array) { ... }; $sth=$dbh->prepare($sql2); $sth->execute; while(($var2)=$sthf->fetchrow_array) { ... };