#!/usr/bin/perl use strict; use warnings; chomp (my $headerline = ); $headerline =~ s/^#// or die "Not a correct headerline"; my @keys=split /:/, $headerline; my @array; while () { chomp; my %hash; @hash{@keys}=split /:/; push @array, \%hash; } # examples print "1st name : $array[0]{'name'}\n"; print "3rd category : $array[2]{'category'}\n"; # traverse entire array for my $idx (0..$#array) { my $row=$idx+1; print "Row $row: ", (map "$_=$array[$idx]{$_} ", @keys), "\n"; } __DATA__ #name:surname:category tiger:woods:golfer tyler:hamilton:f1 james:stewart:supercross roger:federer:tennis