use strict; use warnings; use 5.010; while (){ chomp; # note the string IS always odd if ((length $_) % 2 < 1){ print "Not OK $_ (unbalanced)\n"; next; } if (($_=~/./g)[0,(int((length $_)/2)-1),-1]~~[qw(x x x)]){ print "$_\t\tOK\n"; } else { print "NOT OK $_\n"; } }