in reply to Help in read and write to file at a same time in same file.

There are methods for writing to a file you are reading, but it is much simpler to write to a temporary file and move it over the original when done, e.g.:
my $file = 'fred.txt'; my $tmp = 'fred.txt.tmp' . $$; # habitually I make tmp files unique in + case of multiuser usage. open my $ih, $file; open my $oh, ">$tmp"; while ( <$ih> ) { /My_Name/ and $_ = '## ' . $_ . "\n" ; # although a carriage retur +n is already present print $oh $_; } close $ih; close $oh; rename ( $tmp, $file );

One world, one people