in reply to Regular Expression Question

Please read How do I post a question effectively?. In particular, please wrap code, input and output in <code> tags.

There are multiple ways to achieve your desired result, but I would do it using Look Around Assertions. In your case, your code might look like:

$segment =~ s/^\d{2}(?!\d)/testtext/;
which YAPE::Regex::Explain describes as
NODE EXPLANATION ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- \d{2} digits (0-9) (2 times) ---------------------------------------------------------------------- (?! look ahead to see if there is not: ---------------------------------------------------------------------- \d digits (0-9) ---------------------------------------------------------------------- ) end of look-ahead ----------------------------------------------------------------------

Some side notes:


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.