#!/usr/bin/perl use strict; my %hash; my $raw_file_1 = <) { next if /^file/; my ($val, $key) = split; $hash{$key} = $val; } open( my $file_2, "<", \$raw_file_2 ) or die "Couldn't open \$raw_file_2\n"; while (<$file_2>) { next if /^file/; my ($key, $val) = split; print "$hash{$key}\t$key\t$val\n" if ( defined($hash{$key}) ); }