for (@primes) { last if $_ > $root; # If you have checked bigger primes, you don't want to go through all of them! print("$_ divides $num\n"), return 0 if ($num % $_ == 0); }