my ($file1,$file2,@cols) = @ARGV; open( my ($fh2), $file2 ) or die $!; #just the file2 operations while ( my $row = <$fh2> ) { chomp $row; #print "$row\n"; next if $row =~ /^\s*$/; $row =~ s/^\s+|\s+$//g; my (@fields) = split( /\|/, $row ); # print "$fields[0]\n "; for my $fieldnum (@cols) { if ( exists $hash{ $fields[$fieldnum] } ) { print $fh "$row\n"; next; } } }