my @arr = qw(red green brown); my $hash; $hash = { $_ => $hash || 1 } for (reverse @arr);