use strict; use warnings; # setup bounds my @digits = ( 0 .. 9 ); my $min_digits = 4; my $max_digits = 6; # build the glob string my $glob_string; for my $dignum ( 1 .. $max_digits ) { if ( $dignum <= $max_digits - $min_digits ) { $glob_string .= '{' . join( ',', ( '', @digits ) ) . '}'; } else { $glob_string .= '{' . join( ',', @digits ) . '}'; } } # print the permutations my $num; while ( $num = glob( $glob_string ) ) { print $num, "\n"; }