use strict; use warnings; while () { chomp; my $dic = $_; my (@arr) = $dic =~ /([abort])/g; #get the matching letters my %unique; my $str = join "", grep (!$unique{$_}++, @arr); #make the grepped letters unique print $dic, "\n" if ($str eq 'abort'); #print if the order is a, b, o, r, t }; prints: ------- abort abortion __DATA__ abroad abort abortion boat boaring boart