#!/your/perl/here use strict; use warnings; use Benchmark::Timer; my $t = Benchmark::Timer->new(); $t->start(); my $c = 7*8*9; my $x = $c * int(9876321/$c); my $steps = 0; while ($x > 0) { next if $x =~ /[05]/; # no 0 or 5 next if $x =~ /([1-9]).*\1/; # no repeated digits last; } continue { $x -= $c; $steps++; } $t->stop(); print "$x ($steps steps)\n"; print $t->report(); __OUTPUT__ 9867312 (17 steps) 1 trial of _default (64us total)