my @list=qw(a b c d); my %hash=map{$list[$_] => exists$list[$_+1]?[$list[$_+1]]:[]}(0..$#list);