in reply to Pulling the "stomach" out of a directory of HTML files

Assuming there will always be a match for those two flags, and that there are only one of each of those flags in each page:
($text) = $text =~ /<!-- END MAIN HEADER CODE -->(.*?)<!-- END BOTTOM +CHAPTER\/SECTION NAV CODE -->/s;
Or, as someone pointed out on CB, you can also use index / rindex / substr:
my $start = '<!-- END MAIN HEADER CODE -->'; my $end = '<!-- END BOTTOM CHAPTER/SECTION NAV CODE -->'; my $index = index($text, $start) + length($start); $text = substr($text, $index, rindex($text, $end) - $index);