If your end string is really something static like that, you may not want to use a regex at all. Here's a case insensitive replacement using rindex and substr:
use Benchmark qw(cmpthese);
fbard@devo1:~/spot_camp_layout$ cat rindex
use Benchmark qw(cmpthese);
my $x = ("x" x 100_000)."</body></html>";
my $lc_x = lc($x);
my $end_html = qr{(</body></html>)};
cmpthese(100_000,{
rindex_substr => sub{
my $str = $x;
substr($str,rindex($lc_x,"</body>"),0,"yyyy");
},
regex => sub{
my $str = $x;
$str =~ s|$end_html$|yyyy$1|i;
}
});
Rate regex rindex_substr
regex 18416/s -- -75%
rindex_substr 73529/s 299% --