There's probably a more clever way to delete stuff out of there with a slice that does it really well. I find that these queestions or often answered very well by the guys at perlmonks.org
If you've got 20k keys in your hash, I bet you're pulling it from a database. Perhaps pulling it out with more specific SQL like "minus the ones like 'abc-%'" or "where key not like 'abc-%'" or something woud be more efficient.
while (($k,$v) = each(%foo)) {
delete $foo{$k} if ( $k=~/^bar-/ );
}
> If you can generate an array with all of the keys
Something like
@array=grep /^bar-/, keys %foo;
would probably work, but again I've not tested the speed. They're both variations on a theme though, and I can't see any major speed improvements being likely.