Hi Menagapriya,
Provided that $InputString is your string with both MSH and PID lines you could do the following in a microflow:
Create a Variable String with this expression “substring($InputString, find($InputString, 'MSH'), find($InputString,'PID'))” to get your MSH String.
Create a Variable String with the expression “substring($InputString, find($InputString,'PID'))” to create your PID String.
This would give you the two separate strings but only works if the format of your input string is always the same.
My first option would be to add a HL7 Java Library to the Mendix project and create Java Action to and the parsing tools of the library to work the message.
The microflow is shared here: https://modelshare.mendix.com/models/6b7b3271-86ae-46a0-ae76-ef8f7cb18c9b/conversion-msh-pid
Cheers,
John