#!/usr/bin/perl -w use strict; my $records = {}; # reference to the anonymous uberhash my @record; #could be declared my in the loop where assigned open(DB, "< db.txt") || die "Could not open the database: $!"; while() { chomp; @record = split(/\t/); $records->{$record[0]} = { # we're starting an anon hashref split /\||,/, # split to list on pipe or comma $record[1]}; # done print map "$record[0]\t$_\t$records->{ $record[0] }{ $_ }\n", keys %{$records->{$record[0]}}; } close(DB) || die "Could not close the database: $!"; # now you can set other values in the hash if you like: # $records->{$index}{'description'} = "Randomly indexed item";