Since with all the suggestions here we're just eliminating all spaces in the string, wouldn't simple transliteration ($temp =~ tr/ //d;) be faster/simpler?
Update: EEK! *bangs head* Nevermind, I retract that, $temp =~ s/^\s+|\s$/ would be the best way to do it.