#!/usr/bin/perl -w use strict; use Algorithm::Loops qw( NestedLoops ); my @items= ( 1..6 ); my $choose= 3; my $iter= NestedLoops( [ [ 0..$#items ], ( sub { [ $_+1 .. $#items ] } ) x ($choose-1), ], ); my @choice; while( @choice= @items[$iter->()] ) { print "@choice\n"; # replace above line with your code }