/ ( # capture group ^ # match begin of string .* # match everything \z # match end of string ) (? # if (?{ $+ eq reverse $+ }) # $+ (last captured group) is palindrome # then match nothing (succeed) | # else (?!) # fail on matching nothing (fail the regex) ) /xs # x for readability, s to make . match \n # Note: can match empty string