How to send AT command in the sketch for HM-10 BLE module

Good morning folks!
I was trying to create a little program to use Arduino as a bluetooth remote controller for a second Arduino and was planning using the HM-10 BLE module. I would like to configure the HM-10 automatically with the sketch in the setup but the module seems not receiving the AT-commands. I used the following sketch:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
  
 mySerial.write("AT"); //PING
 if (mySerial.available()) {
  Serial.println(mySerial.read());
 }
  
}

void loop() { // run over and over
  while(flag){
    Serial.println("Loop");
    flag=0;
  }
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

As you can see this is the SoftwareSerial example where I simply put something to send AT commands and receive the answer from BT module.
Why is not working?
If I send the commands manually through the serial all is good, but nothingn happens when I put them in the sketch. The HM-10 is "out of the box", so standard configured.
Again, I would like to configure it automatically as Master or Slave, change the baud rate, change the module name or else.

Any suggestion?

Thank you guys!!

My code is representing below, you can try it.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10,11);
String getword="";
bool getedH=0;
bool getedS=0;

void setup()
{
Serial.begin(115200);
Serial.println("Hardware Read!!");

mySerial.begin(115200);
mySerial.println("Software Read!!");
}

void loop()
{
//get message from software serial to hardware serial.
while (mySerial.available()){
getedS = 1;
getword += (char)mySerial.read();
delay(5);
}
if(getedS){
Serial.println(getword);
getword = "";
getedS = 0;
}

//get message from hardware serial to software serial.
while (Serial.available()){
getedH = 1;
getword += (char)Serial.read();
delay(5);
}
if(getedH){
mySerial.println(getword);
getword = "";
getedH = 0;
}

}