use strict; use Data::Dumper; ###################### ###################### Read in the files open (FILEHANDLE, "$ARGV[0]") || die("Could not open input file"); my @File1 = ; close (FILEHANDLE); open (FILEHANDLE, "$ARGV[1]") || die("Could not open input file"); my @File2 = ; close (FILEHANDLE); ##### my %hash1; ######## Read first file into a hash with first element a key and the entire line the value foreach ( @File1) { chomp; my @file1_elements = split (/\t/,$_); push(@{$hash1{$file1_elements[0]}},$_); } foreach (@File2){ chomp; my @file2_elements = split (/\t/,$_); if exists ($hash1{file2_elements[5}) { print $_ . "\t" . "@{$hash1{$file2_elements[5]}}" ."\n"; ##### Prints the current line in file 2 and adds on the line in file1 where file1[0] == file2[5]. I understand that if there is more than one value i will need to put a loop in to print out all the values but lets leave that out just to simplify. } }