in reply to A regex question
Is there a reason not to just use substitution directly? I.e. $message_body =~ s/blah/something/g? You can fairly easily make it match whole words only, like your example, too, if you want. It seems like you are doing a bunch of work to split it up, modify it, and stitch it back together.
Edit: As for your original question, I'm not exactly sure. It the last element split generates should have its newline intact. One issue I can see, though, is that you are prepending each line after the first with a space. Because in print "$word "; the $word contains the newline character, you've actually put a space after it. That this is a little hard to see is another reason I'd do the "Just do the substitution" method.
|
|---|