This works in a one-liner: $string =~ s/^\s*(.*\S)\s*$/$1/;
Cheers! -Dan -----Original Message----- From: Dr.Ruud [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 08, 2007 2:05 PM To: beginners@perl.org Subject: Re: regex help Jeff Pang schreef: > John W. Krahn: >> Tony Heal: >>> Why doesn't this work? I want to take any leading >>> or trailing white spaces out. >> >> perldoc -q "How do I strip blank space" > > Or generally it could be done by, > $string =~ s/^\s+|\s+$//g; The g-modifier doesn't mean "generally" nor "good". ;-) Please see the suggested perldoc text for the proper ways. I like to use: s/^\s+//, s/\s+$// for $string; but $string =~ s/^\s+//; $string =~ s/\s+$//; may be slightly faster. (like because no localization of $_) -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/