The s
is the substitution operator. It's used like $str =~ s/this/that/
to change an occurrence of "this" to "that" in $str
.
While /
is the most common delimiter, s
uses whatever non-whitespace character immediately follows to set the delimiter to use in the rest of the expression. (This is true of many other operators, such as m
, q
, etc., as well.)
This example says to replace the text (Text)
with an HTML anchor element, using the i
and g
flags.
The reason to use ~
rather than the conventional /
is to avoid the need to escape the /
in the replacement text, like
s/ (Text)/ <a href="..\/images\/text.pdf" target="_top">$1<\/a>/ig if /<p/;
More details can be found by running perldoc -f s
.