#!/usr/bin/perl use warnings; use strict; my $file1 = reader('file1.txt'); my $file2 = reader('file2.txt'); foreach my $col ( 0 .. $#{$file1} ) { print @{ $file1->[$col] }, @{ $file2->[$col] }, $/; } sub reader { my ($file) = @_; my @array; open my $fh, '<', $file or die "can't open file:$!"; while ( defined( my $line = <$fh> ) ) { chomp $line; next if $line =~ m/^$/; push @array, [ split /\s+/, $line ]; } close $fh or die "can't close file:$!"; return \@array; }