On 8/2/07, Tony Heal <[EMAIL PROTECTED]> wrote: snip > Why doesn't this work? I want to take any leading or trailing white spaces > out. > If I remove the remark it works, but I > do not understand why it requires the second line > $string =~ s/^(\s+)(.*)(\s+)$/$2/; snip
Because (.*) matches all but the one space needed by the second (\s+). The . matches everything including the spaces. You can fix this by saying $string =~ s/^(\s+)(.*?)(\s+)$/$2/; to make (.*) match the smallest pattern (non-greedy) instead of the largest (greedy). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/