for my $i (0 .. $#digits) { for my $j (0 .. $#digits) { next if $i == $j; ++$flag if $digit[$i] == $digit[$j]; } }