in reply to Parsing a sentence based on array list

G'day neversaint,

Lorem ipsum text is fine as a typesetting tool; however, assuming you've used it here purely as example text, I'm wondering whether it truly reflects your real data. For instance, if your real data contained 'Data::Dumper', is that one or two words and should the '::' be retained; if your real data contained fractional numbers, would the number be considered a complete word and how would you differentiate between the '.' in the number and a '.' terminating a sentence; and so on and so forth.

Anyway, based solely on the example text you've supplied, this does what you want:

$ perl -Mstrict -Mwarnings -E ' my $line = q{Lorem ipsum dolor sit amet, consectetur adipisicing e +lit.}; my @array = (q{ipsum}, q{sit amet}, q{elit}); my $re = qr{(?:@{[join q{|} => @array]})}; $line =~ s/$re//g; say for split /\W+/ => $line; ' Lorem dolor consectetur adipisicing

-- Ken