use warnings; use strict; my $hdr = ; my @cols = split /\s+/, $hdr; my %hash; # pick a better name while () { my ($row, @vals) = split; for my $i (0 .. $#vals) { $hash{$row}{$cols[$i+1]} = $vals[$i]; } } print "$hash{aaa}{baz}\n"; __DATA__ Log foo bar baz aaa 123 456 789 bbb 987 654 321