use strict; use warnings; use feature 'say'; use PadWalker qw/ closed_over set_closed_over /; use Algorithm::Combinatorics qw/ combinations_with_repetition /; my @data = qw( a b c ); my $state; { say "\tDay one, hard work ahead..."; my $iter = combinations_with_repetition( \@data, 3 ); say @{ $iter-> next } for 1 .. 5; say "\tEnough work for one day!"; $state = closed_over( $iter ); } { say "\tDay 2, back to work..."; my $iter = combinations_with_repetition( \@data, 3 ); $iter-> next; # init set_closed_over( $iter, $state ); say "\tDeadline! Exhaust the iterator!"; while ( my $c = $iter-> next ) { say @$c } } __END__ >perl comb.pl Day one, hard work ahead... aaa aab aac abb abc Enough work for one day! Day 2, back to work... Deadline! Exhaust the iterator! acc bbb bbc bcc ccc