I had made the post above ragrading half the iterations, but I just thought of a better way to calculate primes. Its not as fast, but its a one liner:
while($num <= $max)
{
push @dynamic, $num if (1 x $num) !~ /^(11+)\1+$/;
$num ++;
}
I hope you find this helpful