heya
there are a couple of good example on how to do this in the perlcookbook
the trim function in chapter one might help
the source code from the book is avail at ora.com