# preserves first order, arguments are array refs
sub intersection {
    my @r = @{ shift(@_) };
    my $c = 1;
    my %hash;
    foreach my $e (@r) { $hash{$e} = 1 }
    while (@_) {
        ++ $c;
        my @s = @{ shift(@_) };
        foreach my $e (@s)
        { ++ $hash{$e} if exists( $hash{$e} ) }
    }
    my @r1;
    foreach my $e (@r) { push @r1, $e if $hash{$e} == $c }
    return @r1;
}
