use $handle file handle, you don't need value $query->param($key):

Code:
    if (not($query->upload($key))) {
      if ($query->cgi_error) {
        die "Error uploading picture ".$query->cgi_error."\n";
      }
    } else {
      my $handle=$query->upload($key)->handle;
      ...