#!/usr/bin/env perl -l use strict; use warnings; use autodie; die "Usage: $0 file1 file2\n" unless @ARGV == 2; my (@fhs, $shorter); for (@ARGV) { die "'$_' is zero-length\n" if -z; open my $fh, '<', $_; push @fhs, $fh; } LOOP: while (1) { my @out_line; for (0 .. 1) { my $line = readline $fhs[$_]; if (! defined $line) { $shorter = $_ unless defined $shorter; last LOOP if $shorter != $_; seek $fhs[$_], 0, 0; $line = readline $fhs[$_]; } push @out_line, $line; } chomp @out_line; print @out_line; }