for my $i (0 .. $#digits) { for my $j (0 .. $#digits) { next if $i == $j; ++$flag if $digit[$i] == $digit[$j]; } } #### for my $i (0 .. $#digits) { for my $j ($i + 1 .. $#digits) { ++$flag if $digits[$i] == $digits[$j]; } } #### sub check_duplicates { my $candidate = shift; ++$flag if $candidate =~ /(.).*\1/; } #### sub check_prime { my $candidate = shift; ++$flag if 2 != $candidate =~ tr/2357//; } #### for (my $candidate = 10234; $candidate <= 98765; ++$candidate) { # we want to jump eg from 10992 to 11000 # note not 'next': we've already incremented if the s/// succeeds redo if $candidate =~ s{ ^ (.*? (.) .*? \2) (.*) }{ ($1 + 1) . ("0" x length($3)) }ex; ... } #### print "$candidate\n" unless $bad;