#!/usr/bin/perl -w use strict; use Algorithm::Loops 'NestedLoops'; my( $p, $c ) = @ARGV; my $iter = NestedLoops( [ [ 1..$p ], ( sub { [ $_..$p ] } ) x ($c-$p-1) ], ); my @s; while( @s = $iter->() ) { my @p = (1) x $p; $p[$_-1]++ for @s; print "@p\n"; }