A Perl programmer is asked to write a script to find all the prime numbers. They finish in 5 minutes. "How did you do it so fast?" asks their coworker. "I just used the is_prime function," they reply. "But Perl doesn't have an is_prime function!" yells back the coworker. The Perl programmer laughs. "I know. I wrote it in three lines."
@nixCraft And moreover, as a regular expression.

@michal @nixCraft
sub is_prime {
return !((1x$_[0]) =~ /^.?$|^(..+?)\1+$/);
}

(from illya.sh/the-codeumentary-blog…)

Demystifying The Regular Expression That Checks If A Number Is Prime

Ever wondered how the ^.?$|^(..+?)\1+$ regular expression can tell you if a number is not prime? In this blog post you'll learn how and why it works. Code examples in Java, JavaScript, Python and Perl are provided.

The Codeumentary