foreach my $w (3..100) { foreach my $x (2..$w-1) { foreach my $y (1..$x-1) { foreach my $z (0..$y-1) { next if ($z-$y==$y-$x and $y-$x==$x-$w); ...; } } } }