use Data::Dumper; my (@keys, $format, @data, @sizes); $_ = ; while (/\G(\S+)\s+/g) { push(@keys, $1); push(@sizes, $+[0]-$-[0]); } $format = join("", map { "a$_" } @sizes); while () { # if you want a hashref for each line: my $i; push(@data, { map { ($keys[$i++], $_) } unpack($format, $_) } ); # else, take out references to @keys above and just use this: push(@data, [ unpack($format, $_) ] ); } print Dumper(\@data); __DATA__ Name ID PS Gender Age Month Code Cap Pool LName, FName 99999 99 M 99.9 12/2000 Add 99.99 99.99