#!/usr/bin/perl -w use strict; use vars qw(@all @dup); @all=(["what", "is", "the", "matrix"],["matrix", "reloaded", "is", "no", "good"]); my(%h1,%h2); # for the two halves of your array grep { $h1{$_}=1 } @{$all[0]}; grep { $h2{$_}=1 } @{$all[1]}; @dup = ( [ map { $h2{$_} ? 1 : 0 } @{$all[0]} ], [ map { $h1{$_} ? 1 : 0 } @{$all[1]} ]); print '([', join(',',@{$dup[0]}), '], [', join(',',@{$dup[1]}), "])\n";