Femina,
If you’re willing to alter your technique for pulling segments out of a message this might help.
There is a regular expressions for lists command that the Cloverleaf developers wrote back at the beginning. Here’s how you could use it to get the CAS segments out of the message.
set segmentList [split $msg $segmentSeparator]
set casSegmentList [lregexp $segmentList ^CAS]
This code snippet retrieves all the CAS segments in the entire message (get all list elements that begin with CAS). Then you could use a foreach command to run your code to make your changes to the message and so on.