$segment =~ s/^\d{2}(?!\d)/testtext/; #### 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 ----------------------------------------------------------------------