for (/(?=([A-zA-Z]{8}))/g) { my @l=/./g; print $_, "\n" if $l[2] eq $l[5] and do { my %h; @h{@l}=(); 7 == keys %h; } }