my %o=(this=>33, 'th at'=>44, other=>55,'some thing'=>66,'or another'=>77,none=>88); while (my ($k,$v)=each %o){ my $ModifiedK = $k; next unless $ModifiedK =~s/\s/_/; delete $o{$k}; #This is SAFE !! RTFM. $o{$ModifiedK}=$v; }; print qq(Mod: $_\t=>$o{$_} \n) for sort keys %o"