http://www.perlmonks.org?node_id=577377


in reply to palindrome using regular expressions

This uses the recursive definition of a palindrome:

As for other solutions, there is of course the non-regex way of doing join '',reverse split //, $_ eq $_ but that is probably not what you are looking for.

Note that my $r = "(??{\$palindrome})"; is equivalent to my $r = '(??{$palindrome})';, there is no reference involved (as I thought at first glance).

Update: Minor typo correction

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.