use strict; use warnings; use Data::Dumper; my @fields = qw/num name G A plus S PIM MIN MAJ ten GM GR MT PPG SHG GWG OTG UAG ENG FG/; my $pattern = "A3 A21 A4 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5"; my @data; while (my $line = ) { chomp($line); next if ($line !~ /^\d+ /); my %hash; @hash{@fields} = unpack($pattern,$line); # unpack the data according to the pattern push(@data,\%hash); } print Dumper \@data; ## UPDATE: Reformated code