in reply to Splitting up file

First things first. You need:
use strict; use warnings;

That will never fail you.

To address your problem it looks like you are comparing against the wrong variable in your if statements:

if($string =~ /# __START_CONFIG__/i) { $action=2; }

Should be:

if($value =~ /#\s__START_CONFIG__/i) { $action = 2; }
(I substituted your space for the \s pattern instead, I like it better though if you strictly need a space, I prefer [ ] instead, that's a matter of style, I just like to be very explicit, and it tells me later that I meant to put a space in the pattern. See if these things help.