sub merge {
my (@array1,@array2) = @_;
This won't work. All arguments will go into @array1, and
@array2 will be empty. You need to pass in array references
if you want to preserve which argument is which (although the way your loop functions, it sort of doesn't matter). In fact,
it looks like you are mixing up your array names with your scalar names in the merge function. Maybe you need to
use strict and warnings??
Besides, the subroutine can be done more simply as:
sub merge {
my %hash;
@hash{@_} = ();
sort keys %hash;
}
my @array1 = qw(a b c d e);
my @array2 = qw(c d e f g);
my @merged = merge(@array1, @array2);
print "@merged\n";