#!/usr/bin/env perl use strict; my (%file1,%file2); ## Open the 1st file open(A,"file1"); while(){ chomp; ## Split the current line on tabs into the @F array. my @F=split(/\t/); push @{$file1{$F[0]}},@F[1..$#F]; } ## Open the 2nd file open(B,"file2"); while(){ chomp; ## Split the current line on tabs into the @F array. my @F=split(/\t/); if (defined($file1{$F[0]})) { foreach my $col (@{$file1{$F[0]}}) { print "$F[0]\t$col\t@F[1..$#F]\n"; } } }