sub OpenFF { my %hash; my ($file,$dlmt) = @_; $dlmt = "\t" if ! $_[1]; open(READ,$file) or return(0); my @file = ; chomp(@file); close(READ); my @headers = split($dlmt,shift(@file)); foreach my $line (@file) { my $x = 0; my @columns = split($dlmt,$line); while ($x < scalar @headers) { $hash{$headers[$x++]}{$columns[0]} = $columns[$x]; } } return(%hash); } #### foo.txt ------- ID NAME1 NAME2 AGE 1 donald duck 50 2 mickey mouse 48 3 peter pan 62 4 madre theresa 108 5 banana split 2 #### #!/usr/bin/perl -w use strict; my %foo = OpenFF('foo.txt') or die("Couldn't parse foo.txt, $!\n"); print "The keys are:\n"; print join("\t",keys %foo)."\n"; print "Row 3 is:\n"; foreach (qw'ID NAME1 NAME2 AGE') { print "$foo{$_}{'3'}\t"; } print "Column 'NAME2' is:\n"; foreach (1..5) { print "$foo{'NAME2'}{$_}\n"; } #### The keys are: NAME1 NAME2 ID AGE Row 3 is: 3 peter pan 62 Column 'NAME2' is: duck mouse pan theresa split