sub common_subset { my $a = shift; @_ or return @$a; my %h; @h{@$a} = (); grep { exists $h{$_} } common_subset( @_ ) } #### my @sets = ( [ 0, 1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, ], [ 0, 3, 7, 8, 10, 11, 13, 14, 16, ], [ 0, 1, 2, 3, 5, 7, 8, 10, 11, 12, 13, 14, 16, ], [ 2, 3, 4, 6, 7, 8, 10, 11, 12, 14, 16, ], [ 0, 1, 2, 3, 7, 8, 9, 10, 11, 13, 14, 15, ], ); my @l = common_subset( @sets );