#!/usr/bin/perl -w use strict; use Algorithm::Loops qw( NestedLoops NextPermute ); my @items= qw( prefix first middle last title ); my $choose= 3; my $iter= NestedLoops( [ [ 0..$#items ], ( sub { [ $_+1 .. $#items ] } ) x ( $choose - 1 ), ], # Uncomment next line if you want all sizes <= $choose # { OnlyWhen => 1 }, ); my @choice; while( @choice= sort @items[$iter->()] ) { do { print "@choice\n"; # replace above line with your code } while( NextPermute(@choice) ); }