# Build a hash of word counts foreach ( map @$_, @all ) { $words{$_} ++ } # Create a list of arrays showing repeats @out = map { [ map $words{$_} > 1 ? 1 : 0, @$_ ] } @all;