#!/usr/bin/perl -w @holdspace = (); while (<>) { if (/'(\d)'/) { s/^/(+$1) /g; s/$/;fac=$1/g; unshift @holdspace, $_; } else { if (@holdspace) { print "Newline1\n", @holdspace; @holdspace=(); } print; } if (/Line5/) { print "MeanLine\n"; } }