title: Perl: Sort characters within a string
body: <p>I have two strings, and I would like to test if they are anagrams of each other.</p>
  
  <p>To test if string A is an anagram of string B, the characters of A and B are both sorted. If the resulting sorted strings match exactly, string A and string B are anagrams of each other.</p>
  
  <p>I am <code>split</code>ing the strings up into character arrays, using Perl's <code>sort</code> routine, <code>join</code>ing the characters back together, and testing for string equality with <code>eq</code>:</p>
  
  <pre><code>sub anagram
  {
    my ($s1, $s2) = @_;
  
    return (join '', sort { $a cmp $b } split(//, $s1)) eq
           (join '', sort { $a cmp $b } split(//, $s2));
  }
  </code></pre>
  
  <p>Is there a way to avoid having to convert between the scalar and array types (relying on <code>join</code> and <code>split</code>)? And if so, which method is more efficient?</p>