in reply to Splitting up file

This is fairly easy to do using Perl's flip-flop operator:
#!/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. <br> $ +!"; open OUTFILE2, '>', $prefile2 or die "Could not open $prefile2. <br> $ +!"; open SAMPLE, '<', $data_file or die "Could not open $data_file. <br> $ +!"; my @rawdata; while ( <SAMPLE> ) { if ( 1 .. /# __START_CONFIG__/i ) { print OUTFILE1; next; } if ( /# __END_CONFIG__/i .. eof ) { print OUTFILE2; next; } push @rawdata, $_; } close SAMPLE; close OUTFILE1; close OUTFILE2;
By the way, you can't exclusively lock a file opened readonly. And you should import the flock constants from the Fcntl module instead of using numerical literals.