Contact Us

Scripts: Perl :: String functions :: Library Article #1

Developer's Section

Trim a String in Perl
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3193)

Code and explanation of a Trim function for the Perl Programming language.

There is a simple function you can build to trim strings in your Perl programs.
The function uses two regular expressions to trim a string from the left side of the string as well as one for the right side.

 Code Snippet 1

#!/usr/bin/perl -w

# Perl trim function 

sub trimStr($){

my $string = shift;
           # the first regular expression removes space
           # from the left side
$string =~ s/^\s+//;
           # the second regular expression removes space
           # from the right side
$string =~ s/\s+$//;

return $string;


exit 0;

See other Scripts in String functions

Submit Your Scripts:

System Message:
  • Your Perl script has been sent. Please allow 48 hours for processing.

If you would like to have your Perl scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]