I want the first 2 octets of other string should also be X and X How to do that?

Your first step would be to remove the ^ anchoring your regex to the start of the line but that will cause every pair of numbers separated by a dot, (actually, given your regex, any character, you should escape the '.'), which would be all of them result in in everything becoming 'xx.xx.xx.xx';

So you need to ensure that only the first pair of each quad get modified, so try: s/(?<![0-9.])\d+\.\d+/X.X/g;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.

"Science is about questioning the status quo. Questioning authority".

In the absence of evidence, opinion is indistinguishable from prejudice.

The other string is not at the beginning of a line. Remove the ^.
Also, a dot is a special character in regexes. Backslash it to match literally. You do not need the replaced numbers - no need for capturing parentheses. You do not want the third and fourth numbers to be replaced - you can achieve this by requiring a dot after the numbers to be replaced:

Replace each digit with an x? Hehe, that reminds me to the winning entry (bottom of page) of the 2008 Underhanded C Contest. Sure, blacking out each digit makes sense if you're doing this on paper with a black pen, or with a scanned image you do not want to OCR, but not much in a string replacement.

Another very useful CPAN package to get to know is Regexp::Common, which is a kitchen sink collection of “canned,” known good regular-expression patterns, including ones for IP-addresses of all kinds. Especially useful when you need to validate the contents of a file, or to “future proof” your logic.

(To fully see what I mean, click on that page, then click on the link to the right of the author’s name in the gray-shadowed line above “Module Version.” This shows you all of the packages that are part of this one. Then, if you search for the string “Regexp::Common,” you’ll see about 150 more equally-large ones.