in reply to Splitting up file

In your loop on @rawdata you match on $string, which is undefined. If you replace it with $value, your code works for me.

It might be worth considering to use use strict; and use warnings;, because these point out some errors.

I would also replace the first if with
if($value =~ /# __START_CONFIG__/i) { $action=2; print outfile1 $value; next; }
to ensure that this line ends up in the first file. I didn't encounter problems re-running the script, so I can't help you on that one.