#!/usr/bin/env perl use strict; use warnings; use Data::Dump; my %data = ( 'rendition' => '3', 'automation' => '2', 'saturation' => '3', 'mass creation' => 2, 'automation technology' => 2, 'automation technology process' => 3, ); dd \%data; for my $multi_key (grep y/ / / != 0, keys %data) { next unless exists $data{$multi_key}; for my $any_key (keys %data) { next if $any_key eq $multi_key; delete $data{$any_key} if 0 == index $multi_key, $any_key; } } dd \%data; #### { "automation" => 2, "automation technology" => 2, "automation technology process" => 3, "mass creation" => 2, "rendition" => 3, "saturation" => 3, } { "automation technology process" => 3, "mass creation" => 2, "rendition" => 3, "saturation" => 3, }