in reply to Specific substitution in regular expressions

Hi,
if you were just after the first '99' in your string, just omit the 'g'-Modifier, otherwise use more groupings to do it:
my $reg = '99'; my $replace = 'XX'; my $line = "0165451234599123459935589"; print $line, "\n"; $line =~ s/$reg/$replace/; print $line, "\n"; $line = "0165451234599123459935589"; $line =~ s/(12345)($reg)(12345)/$1$replace$3/; print $line, "\n";
prints
0165451234599123459935589 01654512345XX123459935589 01654512345XX123459935589

Regards,
svenXY