#!/usr/local/bin/perl use warnings; use strict; my @l = <>; my $in_pre = 0; my $div_re = qr/

= 5 and $l[0] =~ /$div_re/o and $l[1] !~ /\S/ and $l[2] =~ /

// and $l[4] =~ m!

! ) { $l[0] =~ /^(.*)$div_re/o or die; my $before = $1; print "$before\n" if length $before; $in_pre = 0 if $before =~ m!\n"; print $l[3]; splice @l, 0, 5; } elsif ($in_pre and $l[0] !~ /\S/) { shift @l; } else { print "\n" if $in_pre; $in_pre = 0; print shift @l; } }