while (my $value = $it->next()) { # stuff if ($it->has_next()) { # for all but the last value } }