# I didn't have the length == 8 line because # I'm only reading one file containing 8-letter words while () { $c = substr ($_, 2, 1); if (substr ($_, 5, 1) eq $c) { my %h; @h{split//,$_} = (1) x 8; print if keys %h == 7; } }