use strict; use warnings; use Data::Dump::Streamer; my @bigram = ( 'aa' .. 'zz' ); # magic! my @testBigrams = split ' ', do {local $/; ;}; # make a "set" of the ones in the list: my %bigram_list; @bigram_list{@testBigrams} = (0) x @testBigrams; # corresponds to (and same size as) @bigram. my @bigrams_existing = map { exists $bigram_list{$_} ? 1 : 0 } @bigram; Dump (\@bigrams_existing); __DATA__ gr an df at he rj dp or te rj kv ap la ne ts ca pe ww