my @required = qw ( apple banana orange pear ); my @collections = ( 'foo pear bar apple', 'apple foo pear orange banana', 'pineapple appearance', ); foreach my $collection ( @collections ) { foreach my $item ( @required ) { $collection .= " $item" unless $collection =~ /\b$item\b/; } } print "$_\n" for @collections;