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