# 1. open the file open FILEHANDLE, $filename or die $!; # 2. look for my first repeated block while( ) { if( /(some-regex-for-the-repeat-block)/ ) { # 3. save this first repeated block to a variable (which is best?) # 4. open the first output file open TEMP, "> $outfile" or die $!; # 5. write the code to this file and close it print TEMP $1, $/; close TEMP or die $!; # 6. repeat to end of file }