# if @ds1_rows is an AofA holding a dataset, then... for my $a ( @ds1_rows ) { # $record1 is an array, not a scalar... you are deref-ing # an arrayref and assigning it to a scalar, which doesn't # make any sense my $record1 = "@$a"; my $bool = ''; # then, further on... # you are assigning each element to $aref # (where is the 'my'?)... for $aref ( @ds2_rows ) { # and then, not using $aref... # instead, you are using $a again my $record2 = "@$a"; #### #Simple solution for union and intersection foreach $e (@a) { $union{$e} = 1 } foreach $e (@b) { if ( $union{$e} ) { $isect{$e} = 1 } $union{$e} = 1; } @union = keys %union; @isect = keys %isect;