foreach $key (%index){ delete $index{$key} if ($key =~ /$test.+/); } #### foreach (keys %index) { delete $index{$_} if /$test.+/ }