use strict; my $n1; my $n2; foreach my $w (3..100) { foreach my $x (2..$w-1) { foreach my $y (1..$x-1) { foreach my $z (0..$y-1) { foreach my $s (1..20) { $n1++; unless ( $x == $w + $s && $y == $x + $s && $z == $y + $s ) { $n2++; } } } } } } print "n1: $n1\n"; print "n2: $n2\n";