my %CommonSampleNames open my $IN1, "file2.txt" or die $!; my $head = <$IN1> ;## again use it if it has a header while(<$IN1>){ chomp $_; my @line = split(',', $_); if(exists $hash1{$line[0]} ){ ## $line[0] is the sample name column $CommonSampleNames{$line[0]} = 1; } } close($IN1);