my %hash; # somewhere before you start to loop over the data ... # within the loop over your data my $signature = join '|', $id2, $sequence; my $structure = { id1 => $id1, id2 => $id2, sequence => $sequence, label => $label, }; $hash{$signature} = $structure; # save it