#!/usr/bin/perl use warnings; use strict; open DATA, "data.txt" or die("Can't open file for reading: $1"); open EXCLUDE, "exclude.txt" or die("Can't open file for reading: $1"); open OUT, ">out.txt" or die("Can't open file for writing: $1"); my $exclude_serial = ; chomp($exclude_serial); my $line_data = ; while ($line_data) { chomp($line_data); my ($serial, $name, $flag) = split /,/, $line_data; # if we've run out of numbers to exclude just print the line to the outfile if (! defined $exclude_serial) { print OUT "$line_data\n"; # if we've not yet reached the serial to exclude, again just print the line } elsif ($serial < $exclude_serial) { print OUT "$line_data\n"; # we must need a new exclude number then, pull it off the file, keeping track # of whether the current or subsequently read exclude serials mean we shouldn't # print the current line } else { my $write_current_line = 1; # assume it's okay unless we find a match do { $write_current_line = 0 if $exclude_serial == $serial; $exclude_serial = ; chomp($exclude_serial) if defined $exclude_serial; } until (! defined $exclude_serial or ($exclude_serial > $serial) ); print OUT "$line_data\n" if $write_current_line; } $line_data = ; }