http://qs321.pair.com?node_id=649285


in reply to Re: regexp - repeatedly delete words expressed in alternation from end of string
in thread repeatedly delete words expressed in alternation from end of string [regexp]

Should only remove the expression from the end of the string. So it's actually a little simpler:
my @words = qw( SA NV LTD CO LLC ); my ($re) = map qr/$_/i, join '|', map quotemeta, @words; while (<DATA>) { chomp; s/(?:\s*\b$re)+$//; print "[$_]\n"; } __END__ Bobs leave SA Warehouse SA LTD Jims Fine Wines CO LLC

Caution: Contents may have been coded under pressure.
  • Comment on Re^2: regexp - repeatedly delete words expressed in alternation from end of string
  • Download Code