use strict; use warnings; my $file1 = make_func (shift); my $file2 = make_func (shift); while (1) { my $line1 = $file1->(); my $line2 = $file2->(); last unless defined $line1 and defined $line2; print "$line1 $line2 \n"; } sub make_func { my $file = shift; open my $FH, "<", $file or die "could not open $file $!"; return sub {my $c = <$FH>; return unless defined $c; chomp $c; return $c } }