#!/usr/bin/perl # http://perlmonks.org/?node_id=1202179 use strict; use warnings; chomp( my @words = ); # find the "banks" in the word list my %banks = map { $_, [ ] } grep !/(.).*\1/, @words; # find what a word "banks" to and save if "bank" exists for ( @words ) { my $banksto = tr///csr; exists $banks{$banksto} and push @{ $banks{$banksto} }, $_; } print "@$_\n" for values %banks; __DATA__ ab aabb aaabbb xxyy xxxyyy