$ cat test.pl use strict; use warnings; use Text::CSV_XS "csv"; my %npn = map { chomp; $_ => 1 } do { local @ARGV = "npn.txt"; <> }; csv (in => "first_file.txt", filter => { 2 => sub { !exists $npn{$_} }});