#!/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"; } } #### #!/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; }