I am fairly new with Perl, and even more so with regex. Have been trying to match the following, but without success:

  • First, 3 to 4 letters (ideally case insensitive)
  • Optionally a space (but not mandatory)
  • Then, also optionally a known big-case letter (M) and a number out of 1,2,3

An example of a valid string would be abc, but also DEFG M2. Invalid would be mem M, for example
What I have so far is:
$myExpr ~= m/^[a-z,A-z]{3,4}M[1,2,3]$/i
Not sure how to make the M and numbers optional

Check Solution