In case if you doing multiple queries with same SELECT, try to put $sth = $dbh->prepare("..."); before cycle loop and $sth->execute($param); inside loop. It should give you more perfomance if loop has significant cycle number.
$sth
= $dbh->prepare("...");
$sth->execute($param);