#!/usr/bin/local/perl use strict; use warnings; my %HashRef = (); my $File1 = 'blah.txt; my $File2 = 'moreblah.txt'; my $outfile = 'blank.txt'; open FILE2, "< $File2" or die "could not open tumour file...\n"; open FILE1, "< $File1" or die "could not open host file...\n"; open( my $out_fh, '>', $outfile ) or die "$!"; while (my $cols = { chomp $cols; my @values = split ',', $cols; for my $i(5..$#values) { push( @{$HashRef{ $values[2] }}, $values[$i]); } } while (my $cols = ) { chomp $cols; my @values = split ',', $cols; my @newarray = ($values[0], $values[1], $values[2], $values[3], $values[ 4]); for my $j(5..$#values) { if($values[$j] =~ m/'REF'/) { push(@newarray, $values[$j]); } elsif( $HashRef{ $values[$j]} =~ m/'REF'/) { push(@newarray, $values[$j]); } else { push(@newarray, " REF "); } } say $out_fh @newarray; } close $out_fh; close file1; close file2;