my @required_items = qw( apple orange pear ); foreach my $collection (@collections) { my %seen = (); foreach my $item ( ... ) { # however you get the items out of $collection $seen{$item} = undef; } foreach my $item (@required_items) { if ( ! exists($seen{$item}) ) { # do something to insert it } } }