use warnings; use strict; use Algorithm::Loops qw(NextPermute); my $number = '123'; my @digits = split //, $number; my @array = ($number); # Add the first permutation push @array, join '', @digits while NextPermute (@digits); print "@array";