in reply to Conceptual doubt in metacharacters : Beginner in perl

Hello Perl_Programmer1992, and welcome to the Monastery!

“The preceding character” means the single, immediately preceding character, in this case m. But the character before that — another m — is not present in the string held by the variable $what, so there is no match. If you change the regex to /com?a/, it matches.

Other metacharacters: + matches one or more of the preceding character; * matches zero or more of the preceding character; . (dot) matches any one (single) character (except a newline). Parentheses () are used for capturing: reading from left to right, the captured strings are available in the special variables $1, $2, etc. See “Metacharacters” under perlre#The-Basics.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Conceptual doubt in metacharacters : Beginner in perl
by Perl_Programmer1992 (Sexton) on Jan 02, 2019 at 07:32 UTC

    Thank for the explanation @Athanasius , so it means that the part of the pattern before the character(in this case 'm') should be same as the original string.

      I find Regexp::Debugger very convenient when trying to find why a regular expression matches or does not match.