in reply to removing the spaces from keys of a complex hash

It looks like you're on the right track here - walk the list of keys producing a new hash with corrected keys, recursing when you encounter a hash-ref.

Your downfall is your lack of:

   use strict;

That's why you didn't notice that you called the key $ckey but referred to it in a number of places as $key:

   if (ref($work_hash{$key}) eq "HASH")

-sam