#!/usr/bin/env perl use strict; use warnings; use autodie; use constant { ID => 0, SYMBOL => 1, TAXON_NAME => 3, GO_ID => 5, GO_NAME => 6, }; my $file = './pm_1076856.tsv'; my %go_hash; open my $fh, '<', $file; while (<$fh>) { next if $. == 1; my @cols = split /\t/; $go_hash{$cols[SYMBOL]}{$cols[ID]}{$cols[TAXON_NAME]}{$cols[GO_ID]} = $cols[GO_NAME]; } close $fh; for my $symbol (sort keys %go_hash) { for my $id (sort keys %{$go_hash{$symbol}}) { for my $taxon_name (sort keys %{$go_hash{$symbol}{$id}}) { for my $go_id (sort keys %{$go_hash{$symbol}{$id}{$taxon_name}}) { print join("\t" => $symbol, $id, $taxon_name, $go_id, $go_hash{$symbol}{$id}{$taxon_name}{$go_id} ), "\n"; } } } } { print "\nData::Dumper Output:\n"; use Data::Dumper; local $Data::Dumper::Indent = 1; print Dumper \%go_hash; } print "\nData::Dump Output:\n"; use Data::Dump; dd \%go_hash;