$rows=$sth->rows; while (($pointer = $sth->fetchrow_hashref) && ($current_count_all <= $stopcount_all)){ $threadID = $pointer->{'threadID'}; if ($threadIDlist !~ /$threadID/) { $threadIDlist=$threadID . "," . $threadIDlist; $threadcount++; #print message list here } }