while ( @row = $sth->fetchrow_array ) { while($time_ran <= $max_time) { $conter++; $time2 = time; $time_ran = $time2 - $time1; } }