#!/usr/local/bin/perl use strict; my $max = 0; 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,$_; $max = $_ if $_ > $max; } close IN; @ar; } ## load the files into arrays my @a=readfile 'f1.lst'; my @b=readfile 'f2.lst'; my @c=readfile 'f3.lst'; ## iterate until all arrays are empty for (my $i = 0; $i <= $max; $i++) { next unless $a[0] == $i || $b[0] == $i ||$c[0] == $i; ## print them out (if they match) printf "%5s", $a[0]==$i ? scalar shift @a : undef; print " | "; printf "%5s", $b[0]==$i ? scalar shift @b : undef; print " | "; printf "%5s", $c[0]==$i ? scalar shift @c : undef; print "\n"; }