use strict; use warnings; my $file1 = <) { next unless /(^\w+)\s+(\w+)/; $data{$1}{dna} = $2; $dnaLen ||= length $2; } close IN; open IN, '<', \$file2 or die "Failed to open file2: $!"; while () { next unless /(^\w+)\s+(\w+)/; $data{$1}{morph} = $2; $morphLen ||= length $2; } close IN; die "No dna data found" unless $dnaLen; die "No morph data found" unless $morphLen; for my $species (sort keys %data) { $data{$species}{dna} ||= '?' x $dnaLen; $data{$species}{morph} ||= '?' x $morphLen; print "$species: $data{$species}{dna}$data{$species}{morph}\n"; } #### species_1: ACCATGATACGATG001001010201001001 species_2: GGTTTCGACGCAGA002010200210120201 species_3: GGACTCAGCGACTA?????????????????? species_4: ??????????????001001110000000101 species_5: ??????????????111001001001000201