foreach $key (keys %index) { print "deleting $key\n"; # delete $index{$key} if ($key =~ /$test.+/); }