GSAD1234 GSAD2345 GSAD4567 #### GSAD1234 \t 123 \t 45 \t no match \t fungus \t protein_x GSAD5678 \t 123 \t 51 \t plant \t fungus \t protein_y \t transporter #### GSAD1234 \t 123 \t 45 \t no match \t fungus \t protein_x #### #!/usr/bin/perl use warnings; use strict; use Text::CSV; use File::Slurp; my $csv = Text::CSV->new({ sep_char => '\t' }); #end of preparation #read data my $file = $ARGV[0] or die "Need to get CSV file on the command line\n"; open(my $data,'<',$file) or die "Could not open file \n"; chomp (my @strings = <$data>); close $data; # read ID list my $id = 'id.txt'; my @ids = read_file("$id", chomp =>1); foreach(@ids) { my @matches = grep(/^($_)/,@strings); print join ",",@matches; }