my $fmt = "x[10]a5x[22]a10x[4]a3a2..."; my %hash; while( <$fh> ) { my( $code, @fields ) = unpack $fmt, $line; $hash->{$code} = \@fields; } ... for my $code ( keys %hash ) { print $hash->{ $code }[ $_ ] for 0 .. 33; }