rows=$sth->rows; %threads; while (($pointer = $sth->fetchrow_hashref) && ($current_count_all <= $stopcount_all)){ $threads{$pointer->{'threadID'}}++; } my $threadCount = scalar keys %threads;