my$key=pop@array; if(!exists($hash{$key})){ $hash{$key}=[$array[-1]]; }else{ nextif(grep{$_eq$array[-1]}@{$hash{$key}});#if the item already exists in the array, skip it
push@{$hash{$key}},$array[-1];# put the item into the array if it does not exist in the array