use strict; use warnings; my $infile = "data.txt"; my $outfile = "peptest.txt"; open(DATA,"<",$infile) || die "Unable to open file '$infile': $!\n"; my $file; # Slurp in the file into memory { local $/; $file = ; } close(DATA); open(OUTPUT,">",$outfile) || die "Unable to open file '$outfile': $!\n"; my ($section) = ($file =~ m/(NAME.*)ADJ/is); my (@lines) = split /\n/,$section; my $i = 0; foreach my $line (@lines) { if ($line =~ m/1235114182/) { my (@cols) = split /\s+/,$line; if ($cols[12] eq "0.00") { print OUTPUT "$lines[$i]\n$lines[$i+1]\n"; } } $i++; } close(OUTPUT); #### 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 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