$marker = "";
# let's use perl's built-in in-place editing
# please check the 'perlrun' documentation for
# explanation of the -i switch, and the 'perlvar'
# documentation for the corresponding $^I variable
{
# $^I = "" <-- no backup file
# @ARGV = ("foo.html") <-- magical <> works on this file
local ($^I, @ARGV) = ("", "foo.html");
while (<>) {
# \Q will escape any special regex chars in $marker
# if any exist -- good safety measure!
s/\Q$marker/$url
\n$marker/;
print;
}
}
####
# stick "$url
" RIGHT BEFORE $marker
s/(?=\Q$marker)/$url
\n/;