use warnings; use strict; my @P = qw/2 2 3 5 11 277412413/; @P= sort { $a<=>$b } @P; # sort to be sure my @D = (1); my @D_new = (); my $p_old = 0; for my $p (@P) { if ( $p == $p_old ) { @D_new = map { $_* $p } @D_new; } else { @D_new = map { $_* $p } @D; } push @D,@D_new; $p_old = $p; } @D= sort { $a<=>$b } @D; print "Factors @P\n"; print "Divisors: @D\n";