my @numbers; for my $i (100 .. 999) { my @num = split(//, $i); foreach my $j (@num) { $j **= 3; } if (sum(@num) == $i) { push @numbers, $i; } }