#!/usr/bin/perl -w use strict; use Algorithm::Loops 'NestedLoops'; my $length= 4; my @chars = ('a' .. 'd'); my $get_combo = NestedLoops([ (\@chars) x $length ]); my @combo; while ( @combo = $get_combo->() ) { print "@combo\n"; }