#Perl script to interleave two text files line by line use strict; die "Usage:\n perl interleave.pl file1 file2 outfile\n" unless $ARGV[2]; open IN1, $ARGV[0] or die "Sorry, couldn't open $ARGV[0]. "; open IN2, $ARGV[1] or die "Sorry, couldn't open $ARGV[1]. "; open OUT, ">$ARGV[2]" or die "Sorry, couldn't create $ARGV[2]."; my ($in1, $in2); #uncomment this next line to stop at end of shorter file #print OUT "$in1$in2" while (($in1 = ) && ($in2 = )); #uncomment this do { } block to continue to end of longer #file, interleaving blank lines when the shorter file runs out. do { $in1 = ; $in2 = ; last unless ($in1 || $in2) ; #break when there's no more data $in1 = "\n" unless $in1; #blank lines for absent data $in2 = "\n" unless $in2; print OUT "$in1$in2"; } until 0 ;