my %category_for_store; for my $category (keys %store_for_category) { for my $store (@{ $store_for_category{ $category }}) { warn "Duplicate category for store '$store': $category_for_store{ $store }, $category" if $category_for_store{ $store }; $category_for_store{ $store } = $category; }; });