http://www.perlmonks.org?node_id=522536


in reply to what is the function should I need to use for trim white spaces ?

Your code is missing an s, so it won't do what you want.

That aside, you could use the following rather obfuscated code:

s/^\s+//g, s/\s+$//g for $value;
But it's probably better just to make a function:
sub trim { local $_ = @_ ? $_[0] : $_; s/^\s+//g; s/\s+$//g; $_ } $trimmed = trim($untrimmed); $trimmed = trim; # Trims $_ by default. @trimmed = map trim, @untrimmed; # Trim a whole list. (readable) push(@trimmed, trim) for @untrimmed; # Trim a whole list. (efficient)