#!/usr/bin/perl use warnings; use strict; die "type file1 and file2 and output" unless @ARGV==3; my ($fin1, $fin2, $fout) = @ARGV; open my $in1, "<", $fin1 or die "Couldn't open '$fin1': $!"; open my $in2, "<", $fin2 or die "Couldn't open '$fin2': $!"; open my $out, ">", $fout or die "Couldn't open '$fout': $!"; <$in1>; <$in2>; # skip headers my %ligs; # lookup table while (<$in1>) { chomp; my ($lig, @fields) = split /\t/; $ligs{$lig} = [@fields]; } while (<$in2>) { chomp; my ($lig, @f2) = split /\t/; if (exists $ligs{$lig}) { my $f1 = $ligs{$lig}; # get corresponding entry from other file my @diffs; for (0..$#f2) { $diffs[$_] = $f1->[$_] - $f2[$_]; } print $out "$lig\t", join(" ", map sprintf("%.3f",$_), @diffs), "\n"; } } #### ... ... }}}}}}}