my $max = 0; while (my @row = $tmp_id->fetchrow_array){ $max = $row[2] if $row[2] > $max; }