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

There's not a built-in. The regexp approach is fine. If you want it to be a sub, just put it in a sub definition:

sub trim_white { my $string = shift; $string =~ s/^\s+//g; $string =~ s/\s+$//g; return $string; } # Usage example: my $trimmed = trim_white( $untrimmed );

Update: For completeness's sake, it might be worth noting that on CPAN you can find String::Util, which includes a function called trim() that does exactly what you're talking about. ...it's been done. ;)


Dave