#!/usr/local/bin/perl use strict; use warnings; open (FH1, "File1.txt")or die("Error opening File1 $!\n"); my %hash1; while(){ next if /(trip|valu1|valu2)/; #skip the header my ($key, $val1, $val2)= split /\s+/; push @{$hash1{$key}}, ($val1, $val2); #hash of anonymous array } close FH1; open(FH2, "File2.txt")or die("Error opening File1 $!\n"); my %hash2; while(){ next if /(trip|value)/; my($key, $val3)=split /\s+/; $hash2{$key}=$val3; } close FH2; #convey common keys into one hash.. my %hash3; my ($key1, $key2); foreach $key1(keys %hash1){ foreach $key2(keys %hash2){ if ($key2 eq $key1){ push @{$hash3{$key1}}, @{$hash1{$key1}}, $hash2{$key2}; } } } #Print to STDOUT print "TRIP\tvalue1\tvalue2\tvalue3\n"; foreach my $key(keys %hash3){ print "$key\t"; print "@{$hash3{$key}}\n"; }