my @keys = qw( id username domain address); # and so on my %addressbook; while (<>) { # or whatever handle my @data = split /\t/; $addressbook{$data[0]} = { map { ($keys[$_] => $data[$_]) } 1..$#keys }; }