#!/usr/bin/perl -w $holdspace = ""; while (<>) { if (/'1'/) { s/^/(+1) /g; s/$/;fac=1/g; $holdspace = $_; $_ = ""; } elsif (/'2'/) { s/^/(+2) /g; s/$/;fac=2/g; $_ .= $holdspace; $holdspace = $_; $_ = ""; } elsif (/'3'/) { s/^/(+3) /g; s/$/;fac=3/g; $_ = "Newline1\n" . $_; $_ .= $holdspace; $holdspace = ""; } if (/Line5/) { $_ .= "MeanLine\n"; } print; }