#!/usr/bin/perl use warnings; use strict; my (@text, @gcard, @pcard); my ($ntext, $ftext, $gtext, $ptext); open (OUT, ">ban.test") or die "Can't open ban.test for write: $!\n"; while (){ if (/^n10/) { @text = "g total"; @gcard = "g -----"; @pcard = "p x "; print OUT "$_"; } elsif (/^n01/) { $ntext = (split (/;/)) [0]; $ntext =~ s/n01//g; $ftext = substr($ntext,0,5); $gtext = "-----"; $ptext = " x "; push(@text, $ftext); push(@gcard, $gtext); push(@pcard, $ptext); print OUT "$_"; } else { print OUT "$_"; } } print OUT "\n"; print OUT "@text\n"; print OUT "@gcard\n"; print OUT "@pcard\n"; __DATA__ line1 line2 n10total n01chocoloate;more stuff n01vanilla;more stuff