in reply to writing array as pairwise

As GotToBTru said, your code isn't very useful without sample data.

But if I have understood your problem well, there is one obvious solution. Uniqueness means hash:

sub existsPair { our %pairs; my (@pair) = sort @_; local $" = "~~"; # Only works as long as ~~ can't appear in one of t +he inputs values return $pairs{"@pair"}++; } existsPair "Hello", "World"; # false existsPair "Hello", "World"; # true existsPair "World", "Hello"; # true existsPair "He", "lloWorld"; # false
The hardest part of the job is to find a way to stringify the pair in a way that is actually unique, it can be by using an invalid character as a separator, or using pack for prepending the size of the first string, or whatever works.