#!/usr/bin/perl -w use strict; my @data=(); while () { if (my $flag_EOR = /NAME /.../ADJ TO TOTALS:/) { push (@data, $_); #accumulates this record's data # add print "$flag_EOR\n"; to see what is happening... next unless $flag_EOR =~ /E0$/; } #print header/trailer and only the zero lines if (my @lines = grep{/^\d+.*\s*0\.00\s*$/}@data) { print $data[0]; # header of record print @lines; # lines that start with numbers and # end with 0.00 print $data[-1]; # trailer of record } @data=(); } =prints I manually chopped lines down to prevent word wrap NAME DOE, JOHN HIC 1111111111 ...blah... 12351141821118 111809 23 001 71010 ... 0.00 CO-18 31.00 0.00 12351141821118 111809 23 001 74150 ... 0.00 CO-18 199.00 0.00 12351141821118 111809 23 001 72192 ... 0.00 CO-18 182.00 0.00 ADJ TO TOTALS: PREV PD INTEREST 0.00 LATE FILING CHARGE 0.00 NET 84.25 =cut __DATA__ REND PROV SERV DATE POS NOS PROC MODS BILLED ALLOWED DEDUCT COINS GRP/RC AMT PROV PD ________________________________________________________________________________________________________________________________ NAME DOE, JOHN HIC 1111111111 ACNT 1111111 ICN 1111111111111 ASG Y MOA MA01 MA18 12351141821118 111809 23 001 71010 26 31.00 0.00 0.00 0.00 CO-18 31.00 0.00 N347 12351141821118 111809 23 001 70450 26 142.00 44.70 0.00 8.94 OA-45 97.30 35.76 N265 PR-2 8.94 12351141821118 111809 23 001 74150 26 199.00 0.00 0.00 0.00 CO-18 199.00 0.00 N347 12351141821118 111809 23 001 72192 26 182.00 0.00 0.00 0.00 CO-18 182.00 0.00 N347 12351141821118 111809 23 001 72131 26 195.00 60.61 0.00 12.12 OA-45 134.39 48.49 N265 PR-2 12.12 PT RESP 21.06 CLAIM TOTALS 749.00 105.31 0.00 21.06 643.69 84.25 ADJ TO TOTALS: PREV PD INTEREST 0.00 LATE FILING CHARGE 0.00 NET 84.25 CLAIM INFORMATION FORWARDED TO : XXXXXX XXXXXXXX INSURANCE CO