my $it = tqdm(100); while (my $i = $it->next) { ... } #### use warnings; use strict; { package Iterator; use overload '<>' => sub { my $self = shift; if (wantarray) { my @all; while (defined( my $x = $self->() )) { push @all, $x } return @all; } else { return $self->() } }; sub new { my $class = shift; my @values = @_; my $i=0; return bless sub { if ($i>=@values) { $i=0; return } return $values[$i++]; }, $class; } } use Test::More tests=>2; my $it1 = Iterator->new(-5..5); my @o1; while (<$it1>) { push @o1, $_; } is_deeply \@o1, [-5,-4,-3,-2,-1,0,1,2,3,4,5]; SKIP: { skip "need Perl >= v5.18 for overloaded <> in list context", 1 unless $] ge '5.018'; # [perl #47119] my $it2 = Iterator->new(-5..5); is_deeply [<$it2>], [-5,-4,-3,-2,-1,0,1,2,3,4,5]; }