You need to build a new message data from the segments that you wish to keep. What I have done in the past is to get msgdta from $mh, foreach segment that does not match your criteria, start adding the segment into a new list. The join the list and set msgdta from the $mh to the new value.
This works and only takes a few lines of code.