#!/usr/bin/env perl use strict; use warnings; use autodie; my ($in1, $in2, $out) = qw{tmp01 tmp02 tmp11_quick}; my (%data, @headings); { open my $fh, '<', $in1; while (<$fh>) { if ($. == 1) { push @headings, split; } else { my ($pep, $prot) = split; push @{$data{$pep}}, $prot; } } } { my $fmt = "%-9s %-9s %-10s %-8s\n"; open my $fh_in, '<', $in2; open my $fh_out, '>', $out; while (<$fh_in>) { my ($id, @rest) = split; if ($. == 1) { printf $fh_out $fmt, @headings, @rest; } else { for (@{$data{$id}}) { printf $fh_out $fmt, $id, $_, @rest; } } } }