#!/usr/bin/perl use strict; my($FILE, $count, $mode); $count = 0; $mode = 0; while(){ if(//){ open FILE, "> $count" or die "Couldn't open file"; # print FILE "\n"; print FILE "\n"; print FILE "\n"; } if(//){ $mode = 1; } if($mode == 0){ print FILE $_; } if(/<\/refentryinfo>/) { $mode = 0; } if(/The template for this document tried to insert/){ close FILE; unlink "$count"; open FILE, "> /tmp/$$"; } if(/<\/refentry>/){ close FILE; $count++; } }