my @head = split /\t/, <$fh>; my $ref = {}; undef @{$ref}{@head}; # pre-allocate the hash and its keys for( <$fh> ) { @{$ref}{@head} = split /\t/; # do something with the data here }