my @array = qw /a b c d e f/; my $hash; my $val = 1; ($hash->{pop @array}, $val, $hash) = ($val, $hash, undef) while @array; $hash = $val;