#!/usr/bin/perl use warnings; use strict; use Data::Dump qw[ pp ]; #subroutine: read in hash tables my $hash1=shift; open (my $fh1, "<",$hash1) or die "$!"; my %h1=(); while (<$fh1>) { chomp; my ($k1,$v1)=split /\t/; $h1{$k1}=$v1; } my $hash2=shift; open (my $fh2, "<",$hash2) or die "$!"; my %h2=(); while (<$fh2>) { chomp; my ($k2,$v2)=split /\t/; $h2{$k2}=$v2; } my %newhash = map { $_ => join ',', @h2{ split ',', $h1{ $_ } }; } keys %h1; while (my ($k, $v) = each %newhash) { print $k, "\t@{$newhash{$k}}\n"; }