#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(first);

my ($txt1, $txt2, $txt3) = @ARGV;
open my $fh1, $txt1 or die $!;
my @data1 = map { chomp; my @c = split / /; $_ = \@c } <$fh1>;
close $fh1;
open my $fh2, $txt2 or die $!;
my @data2 = map { chomp; my @c = split / /; $_ = \@c } <$fh2>;
close $fh2;

open my $fh3, '>', $txt3 or die $!;
foreach my $d1 (@data1) {
if (my $e = first { $_->[0] eq $d1->[0] } @data2) {
printf $fh3 "%s %s %s %s %s\n", $d1->[0], $e->[1], $d1->[1], $d1->[2], $d1->[3]
}
}
close $fh3;