use warnings; use strict; use Tie::File; tie (my @file1, 'Tie::File', $filename1) or die $!; tie (my @file2, 'Tie::File', $filename2) or die $!; # sortieren @file1 = sort(@file1); @file2 = sort(@file2); open (OUT, ">$outfile") or die $!; my $i = 0; my $j = 0; # indices fuer file1, file2 while ($file1[$i] or $file2[$j]) {  # absicherung fuers ende  unless (defined $file1[$i]) {    print OUT $file1[$j]; $j++; next;  } # unless  unless (defined $file2[$j]) {    print OUT $file2[$i++]; next;  } # unless  # vergleiche zwei Zeilen  my $compare = $file1[$i] cmp $file2[$j];  if ($compare < 0) { # file1 ist kleiner    print OUT $file1[$i++];  }  elsif ($compare > 0) { # file2 ist kleiner    print OUT $file2[$j++];  }  else { # gleich gross    $i++; $j++;  } } # while close (OUT); untie(@file1); untie(@file2);