Q:

How can we write the regular expression in Perl with back referencing

I am trying to back referencing with matched string in one liner code. below is the sample record. Please some one help on this.Thanks in advance.
sample Record:

127.0.0.11 [28/Aug/2017:12:23:21 ] 

perl -pe 's/^(\d+.\d+.\d+.\d+)( *$)/\1__/' samplefile.txt

Here i want the output as :
127.0.0.11__

A:

The problem with your code is that it expects an IP address, followed by optional spaces, followed by the end of the line. But your actual data contains other other text ([28/Aug/2017:12:23:21 ]).
You can do this instead:
perl -pe 's/^(\d+\.\d+\.\d+\.\d+).*/$1__/' samplefile.txt

.* matches any remaining text on the line.
Also, you don't want a backreference here: A backreference looks like \1 and is part of regex syntax. But the right-hand side of a substitution is not a regex, it's a double-quotish string. And after a successful regex match you use the capture variables $1, $2, ... to refer to matched substrings.

