How to read serial data

How to store message content from serial moniter into string variable. Below is the code I got to work on. When user sends the
message from phone, it is received by GSM which is then given to Arduino to produce output. The
message is displayed in msg() function. I want to take that message in a variable and use for if else statement.
How to take that message in a variable?

#include <SoftwareSerial.h>

SoftwareSerial mySerial(9, 10);

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  delay(100);
  
}


void loop()
{
  if (Serial.available()>0)
 msg();
 if (mySerial.available()>0)
   Serial.write(mySerial.read());
   
}


 void msg()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  mySerial.println("AT+CMGR=2");
  delay(1000);
}

This should give you the necessary information: