chomp( my @file1 = do { open FH, (+shift); } ); chomp( my @file2 = do { open FH, (+shift); } ); my @file3; while( @file1 && @file2) { push @file3, join(' ', shift(@file1), shift(@file2)); } open FH, ">output"; print FH join($/, @file3, ''); close FH;