#!/usr/local/bin/perl -w use strict; my @words = qw/ beriberi coco couscous deed toot toto tutu assa saaa /; for (@words) { print "$_\n" if /^(\w+)\1|(\w+)(\w+)\3\2$/ # $x$x | $x$y$y$x }