title: Perl function to find the longest word from each separate array
body: <p>I have a task:</p>
  
  <p><strong>There are several arrays, each element of which is a word. Create a function which finds the longest word from each given array and returns the result as a list. References to arrays should be passed as arguments to the function.</strong></p>
  
  <p>This function gives me the longest word from two arrays. I just didn't get it how to make it find the longest words from each separate array.</p>
  
  <pre><code>use strict;
  my @arr1 = qw/one two three/;
  my @arr2 = qw/four five seven/;
  my $arr1 = \@arr1;
  my $arr2 = \@arr2;
  my @sorted_words;
  
  sub func {
    for (@_) {
      for (@$_){
       @sorted_words = sort {length($b) &lt;=&gt; length ($a)} $_;}
    }
    print "The longest word is: $sorted_words[0]\n";
  }
  func($arr1, $arr2);
  </code></pre>