in reply to
You probably want to use substr instead of a regex, because there is a length parameter for counting from the start, or negative offset for counting from the end. And to only cut the first 50 chars in the first line, and last 30 in the last, you can use the variable $. (line number, which is 0, so false on the first line) and eof (which will be true on the last). So :
RemoveHeader() unless $.;
RemoveFooter() if eof;
If you intend to use your script on several files at once, have a look at eof on how to reset $. at the start of each file.