for $ord (0..5) { # set $key and $val for this iteration, and: $hash{$key}{value} = $val; $hash{$key}{order} = $ord; }