Why did you add the '?'s ? They actually mean that the dot may be ignored so of course your regex doesn't do what you want. And even without that, by default regular expressions in perl search for a given pattern anywhere in the string. You need to add the token ^ or \A (see perlre and perlreref) to only match from the beginning of the line or string.
Anyway, in this case regular expressions are probably not the right tool, substr seems more appropriate and easy to use.
BTW, grep selects items in a list, $strTest is a single item, so grep is not needed here.
Edit: added "probably" in "regular expressions are not the right tool". Although it looks to me that it would be far better for the op to use substr because it does not have all the side effects, hidden rules and modifiers of regexes, I don't know for sure that the fifth char is the only thing that need to be checked.
In reply to Re: Perl RegEx doubt
by Eily
in thread Perl RegEx doubt
by swissknife
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |