#!/usr/bin/perl my @tmp1 = map { chomp; [ split /\s+/, $_, -1 ] } `cat tmp01`; # (*) my %tmp2 = map { chomp; my @a = split /\s+/, $_, -1; ($a[0], \@a) } `cat tmp02`; print join "\t" @$_, @{ $tmp2{$$_[0]} }, "\n" for @tmp1; # (*) instead of `cat tmp01` it is more safe to: #use Path::Tiny; #path("tmp01")->lines_utf8({chomp => 1});