unless (@ARGV == 3) { print "Use as follows: perl program.pl in1.file in2.file output.file\n"; die; } my $in1 = $ARGV[0]; my $in2 = $ARGV[1]; my $fout = $ARGV[2]; open ONE, $in1; open TWO, $in2; open foutname, ">$fout"; my %hash1; my @hit; while (){ chomp; my @hit = split(/\t/, $_); #start them as "0" for "no duplicates" $hash1{$hit[0]}=0; } close ONE; my @col; while (){ chomp; my @col = split(/\t/, $_); #increment the counter if %hash1 has what we're looking for. ++$hash1{$col[0]} if(exists($hash1{$col[0]})); } my @dups = grep { $hash1{$_} > 0 } keys %hash1; for my $k (@dups) { print foutname "$k\t$hash1{$k}\n"; } close TWO; close foutname;