use strict; use warnings; use Data::Dumper; my $i = 0; my $line = ; chomp($line); my $colums = { # hash ref to hold colum numbers map { $_ => $i++ } # map each column to a hash and give it the index split(/\|/,$line) # split it on the pipe and send it to map }; print Dumper($colums); my $rows; foreach my $line () { chomp $line; push @$rows, [split(/\|/, $line)]; } print "Record 1: first = " . $rows->[0][$colums->{first}]; __DATA__ title|first|last|room|phone|email Mrs|Linda|Caralo|201|148|she@borg.org Miss|Jean|Androno|317|167|j@alo.com Mr|Steve|Paterman|101|100|steve@net.net