To avoid this inefficiency, you could always tie your own hash which didn't clobber the original values, by not implementing CLEAR. So your above line becomes.
%hash = split /X/, 'fooXbar' # added the missing comma ;)
depends how far you want to go. Full example as follows...
(BTW I did try to do this with Tie::StdHash, but couldn't figure it out)
#!/usr/bin/perl
use strict;
use Data::Dumper;
tie my %hash, 'ExpandingHash';
$hash{'still'} = 'here';
%hash = split /X/, 'fooXbar';
print Dumper(\%hash);
# I also added a new clear method, which you could use like this.
# tied(%hash)->FORCE_CLEAR;
__OUTPUT__
$VAR1 = {
'foo' => 'bar',
'still' => 'here'
};
#==================================================================
package ExpandingHash;
use strict;
sub TIEHASH { my %self; bless \%self, shift }
sub FETCH { $_[0]->{$_[1]} }
sub STORE { $_[0]->{$_[1]} = $_[2] }
sub FIRSTKEY { each %{$_[0]} }
sub NEXTKEY { each %{$_[0]} }
sub CLEAR { } # NOT IMPLEMENTED
sub DELETE { delete $_[0]->{$_[1]} }
sub EXISTS { exists $_[0]->{$_[1]} }
sub FORCE_CLEAR { %{$_[0]} = () }
---
my name's not Keith, and I'm not reasonable.