#!/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; }