in reply to updating a file

This code 'works' for me, well, for some strange distorted definition of 'works.' I think the problem here is that you are trying to update the current like, but you've just read the current line so the write happens on the next line. What I get when I run this is a horribly garbled header file.
You could do this in a number of ways. The most straight forward would be to open one file for reading, one file for writing, and itterate through the read file, replacing the desired lines as you go.
use File::Copy; open(RFH, "<ReadFile.h") or die "Trying:$!"; open(WFH, ">WriteFile.h") or die "Trying:$!"; while(<RFH>) { s/search/replace/; print WFH; } close RFH; close WFH; move ("WriteFile.h", "ReadFile.h") or die "With a vengance:$!";
I didn't actually run this, but it should be close. You might want more descriptive diemessages.

The idiomatic way to do this would be with an 'in place edit' that does the file move for you.

$^I = '.old'; @ARGV = ("header.h"); while (<>) { s/search/replace/; print; }
This will save the old file as "header.h.old" for you.
(I did run this code) BTW: The $^I is equivalent to the '-i' switch mentioned above by broquaint

Ira,

"So... What do all these little arrows mean?"
~unknown