s/^\s+|\s+$//g; #### %hash = map { $v = $hash{$_}; s/^\s+|\s+$//g for $v,$_; $_,$v } keys %hash; # another way which doesn't copy the entire has, just the keys for my $key (keys %hash) { my $value = delete $hash{$key}; for ($key, $value) { s/^\s+|\s+$//g; } $hash{$key} = $value; }