my %data; open FILE, '<', 'gravity' or die; while( ) { my @fields = split ' ', $_; $data{ @fields[ 0, 1 ] } = join "\t", @fields; } close FILE; open FILE, '<', 'magnetics' or die; while( ) { my @fields = split ' ', $_; ## Pad the hash if we didn't see this date/time in the gravity file $data[ "@fields[ 0, 1 ]" } //= join "\t", @fields[ 0,1 ], ('n/a') x 3; $data{ "@fields[ 0, 1 ]" } .= join "\t", @fields[ 2 .. $#fields ]; } close FILE; open FILE, '<', 'bathymetry' or die; while( ) { my @fields = split ' ', $_; ## Pad the hash if we didn't see this date/time before (How many fields added by the magnetics?) $data[ "@fields[ 0, 1 ]" } //= join "\t", @fields[ 0,1 ], ('n/a') x ???; $data{ "@fields[ 0, 1 ]" } .= join "\t", @fields[ 2 .. $#fields ]; } close FILE; for my $key ( sort keys %data ) { print $data{ $key }; }