#!perl -w use strict; my $buffer=""; my $suppress = 0; my @field; my %newline; $newline{$_} = 1 for qw(MSH); my %skipaccount; $skipaccount{$_} = 1 for qw(77403 77404 77406 77407 77408 77409 77411 77412 77413 77414 77416 77418); my $infile = 'c:/rx_q.008'; my $outfile = 'c:/ftpscript/idxfile.txt'; open IN, "<$infile" or die "Couldn't open $infile, $!"; open OUT,">$outfile" or die "Couldn't open $outfile, $!"; while () { #### # Ok now $_ has scalar input from #### chomp(); #### # and it's newline chomped # here is where it is confusing, there is nothing in @field, # let alone at $field[0] , do you mean to split up $_ into @field ??? #### if ($newline{$field[0]}) { processbuffer(); } #### # OK , I am certain this is not doing what you expect #if ( index($newline{$_}, $skipaccount{$_}) != -1) { # $suppress = 1 if $skipaccount{$field[7]}; #} # What you're aiming at (IMHO) is to set suppress to 1 if # the item at index 7 in your fields array (which is split from $_ right??) # is a member of the skipaccount hash. # the if (index($newline{$_} ) makes no sense to me, not in the least with # the data that appears to be in those objects. #### $buffer .= "$_\n"; } # Personally I prefer calling functions like this with an arg, rather than # relying on a globar ($buffer in this case). processbuffer(); sub processbuffer { print OUT $buffer unless $suppress; $buffer=""; $suppress = 0; }