my @fieldnames = qw /S_10 S_11 S_12 S_13 S_14 S_15 T_10 T_11 T_12 T_13 T_14 T_15/; # Note you could also make it dynamic and generate it from the input my %params; while (<$Param>) { my ($index, @values) = split /,/, $_; $params{$index} = { map {$fieldnames[$_], $values{$_}} 0..15;} }