$text =~ s/(^\s+|\s+$)//g [download]
In reply to Re: removing the white spaces by davidrw in thread removing the white spaces by Anonymous Monk