use Algorithm::Loops qw(NestedLoops); use List::Util qw(reduce); my @factors = (2,3,5); # Assmue increasing sequence my $seq_len = 10; my $depth = int( $seq_len ** (1/@factors)) + 1; my @seq; my @list= NestedLoops( [ ( [ 0..$depth ] ) x @factors ], sub { push @seq, reduce {$a * $b} map {$factors[$_]**$_[$_]} 0..$#_;}, ); my @sorted = sort {$a <=> $b} @seq; print "$sorted[$_] " foreach 0..$seq_len-1;