sub existsPair { our %pairs; my (@pair) = sort @_; local $" = "~~"; # Only works as long as ~~ can't appear in one of the inputs values return $pairs{"@pair"}++; } existsPair "Hello", "World"; # false existsPair "Hello", "World"; # true existsPair "World", "Hello"; # true existsPair "He", "lloWorld"; # false