$| = 1; $n = 0; %full = (); for (my $i = 1; $i <= 10000; $i++) { for ($j = 1; $j <= sqrt($i); $j++) { if ($i % $j == 0) { $r = $i / $j; $q = $i . $j . $r; if (length($q) == 9) { if ($q =~ /1/ && $q =~ /2/ && $q =~ /3/ && $q =~ /4/ && $q =~ /5/ && $q =~ /6/ && $q =~ /7/ && $q =~ /8/ && $q =~ /9/) { addNum($i,$j,$r); } } } } } exit; sub addNum { my ($x,$y,$z) = @_; if ($y < $z && ! $full{$x}) { $full{$x} = 1; $n += $x; print "$y $z $x: total: $n\n"; } elsif (! $full{$x}) { $full{$x} = 1; $n += $x; print "$z $y $x: total: $n\n"; } }