Try putting this in your loop instead:
if ( /Range1/ ) {
$header_lines = $.;
}
I think what's currently happening is that everytime through the loop, you are setting $header_lines to the current line number ($.). The code "last if /Range1/;" quits out of your loop when $_ matches Range1. So you would only be setting the first 21 lines, and then quitting, and then erasing all the lines.