#!/usr/bin/perl
# Open File - Read File Contents Then Modify & save contents
use warnings;
use strict;
# Specify name of file
my $data_file = 'sample.pm';
# Name of temp file 1
my $prefile1 = '/tmp/123456.beg';
# Name of temp file 2
my $prefile2 = '/tmp/123456.end';
# Open File and read it all in to rawdata
open OUTFILE1, '>', $prefile1 or die "Could not open $prefile1.
$!";
open OUTFILE2, '>', $prefile2 or die "Could not open $prefile2.
$!";
open SAMPLE, '<', $data_file or die "Could not open $data_file.
$!";
my @rawdata;
while ( ) {
if ( 1 .. /# __START_CONFIG__/i ) {
print OUTFILE1;
next;
}
if ( /# __END_CONFIG__/i .. eof ) {
print OUTFILE2;
next;
}
push @rawdata, $_;
}
close SAMPLE;
close OUTFILE1;
close OUTFILE2;