Perl regex question

$var=~ s#(\n?<a>.*?</a>\n)##s
$pat=$1

Recently i came across this bit of a code.
Can someone please explain the function of these two line?

Appears to removing anything between the <a> and </a> tags in an html file in the first line.

The next line that uses $1 assigns the value that matches the pattern is assigned to pat. In this case it assigns to pat what is being removed.

Seems like it removes the first occurrence of the substring that matches the pattern:

newline, followed by <a> </a> tags and the minimal text between them, followed by newline

from the variable $var. And then assigns the substring (that matched the pattern) to the variable $pat.

tyler_durden

Thanks a lot for ur replies. But I have one more doubt.
Are the #'s being used as delimiters here? If so then what is the purpose of ## at the end of it all?

Check out the perl operators documentation (perlop) at Perl version 5.10.0 documentation - perldoc.perl.org. It has a very nice and detailed explanation of the substitution operator, besides other things.

Hope that helps,
tyler_durden

Ummm ... sorry but I still could not find an explanation for these #'s ... Could someone please explain it to me?