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


in reply to repeatedly delete words expressed in alternation from end of string [regexp]

while (s/\s*$RE$//) {}
or
s/(\s*$RE)*$//;
will get you there without leaving trailing spaces in the finished $_. (Update: made it a little easier to read.)