use Text::Soundex 'soundex'; my @words = qw( Cow Phone Speaker Phone Hello World Phon Speaker Clock Phon Torld Hello Hello Worlx ); while( @words ) { push @pairs, [ shift @words, shift @words ]; } @pairs = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [ join( '' => sort { $a cmp $b } ( soundex @$_[0], soundex @$_[1] ) ), $_ ] } @pairs; for( @pairs ) { print "@$_\n"; } #### Cow Phone Clock Phon Torld Hello Hello World Hello Worlx Speaker Phone Phon Speaker