#!/usr/bin/perl my $datafile = "sample.pm"; open( I, $datafile ) or die "open failed on $datafile: $!"; my @editable; my ( $bgn, $end ) = ( '', '' ); my $save = \$bgn; while () { if ( defined( $save )) { $$save .= $_; $save = undef if ( /^\#\s+__START_CONFIG__/ ); } elsif ( /^\#\s+__END_CONFIG__/ ) { $end .= $_; $save = \$end; } else { push @editable, $_; } } # $bgn holds all input up to and including "# __START_CONFIG__" # $end holds "# __END_CONFIG__ and all input that follows it # @editable holds all lines between $bgn and $end