my $infh = IO::File->new("< data") or die; local $_ = $infh->getline; s/LV /LV_/g; # :-) my @column_names = split; my @records; while ( $infh->getlines ) { my %rec; @rec{@column_names} = split; push @records, \%rec; } return @records; # or simply return map { my %r; @r{@c} = split; \%r } $infh->getlines;