in reply to returning variable from within regex

example data:
Original pattern: TMTMTMTMTETVTITITITX
the X is removed earlier in the program as it never occurs in the larger sequence therefore when i search the pattern is never found.
modified pattern:TMTMTMTMTETVTITITIT
However... the character which X represents (which is any alphabetical character) must be found from the larger pattern.hence the a-z then i search through the larger string untill the pattern is found
target pattern: TMTMTMTMTETVTITITIT[M]or[Q] etc
and ideally remove the completed pattern which matched the regex so $var4 would equal TMTMTMTMTETVTITITITM or TMTMTMTMTETVTITITITQ apologies for being verbose.