#!/usr/bin/perl use strict; sub readfile { my $fn=shift; my @ar; open IN,"<$fn" || die "Couldn't open '$fn': $!"; ## snarf the header scalar ; ## read the rest while () { chomp; push @ar,$_; } close IN; @ar; } ## load the files into arrays my @a=readfile '1'; my @b=readfile '2'; my @c=readfile '3'; ## iterate until all arrays are empty while (defined @a || defined @b || defined @c) { ## find the lowest value my $s; $s=$a[0] < $b[0] ? $a[0] : $b[0]; $s=$s < $c[0] ? $s: $c[0]; ## print them out (if they match) printf "%5s", $a[0]==$s ? scalar shift @a : undef; print " | "; printf "%5s", $b[0]==$s ? scalar shift @b : undef; print " | "; printf "%5s", $c[0]==$s ? scalar shift @c : undef; print "\n"; }