#! /usr/bin/perl use strict; use warnings; use Data::Dumper; local $Data::Dumper::Useqq = 1; use Getopt::Long qw(GetOptions);; ... open(my $table1,'<', $input) or die "$! - [$input]"; #input file open(my $table3, '+>', $output) || die ("Can't write new file: $!"); #output file ... chomp( my @header_for_table1 = split /\t/, <$table1> ); print $table3 join "\t", @header_for_table1, "name1", "name2", "\n"; { no warnings 'uninitialized'; while(<$table1>){ chomp; my %row; @row{@header_for_table1} = split /\t/; print $table3 join ( "\t", @row{@header_for_table1}, @{ $lookup{ ... } // [ "", "" ] }), "\n"; } }