in reply to Preserve original text formatting.

i guess it's all related to the split or the join

I would guess so too. You split on /\s+/ but you join with " " so there's clearly going to be a change in the whitespace there if you have anything other than single whitespaces between the words in your input.

Since you check for \b anyway, why not split on that instead and then check each field for an alpha character before doing your comparison? You could then join on ''.

Alternatively look into using one of the many text parsing modules.

Replies are listed 'Best First'.
Re^2: Preserve original text formatting.
by larsb (Novice) on Sep 10, 2015 at 13:37 UTC

    Thanks a lot, certainly seems like a better solution. Will for sure try it out.

    I'm quite new to perl and certainly a novice regarding regex so I'm sure there is plenty mistakes on that front.

      If you say that you “are new at this,” then you are certainly off to a good start.   :-)

      hippo, are there any particular text-parsing modules that you might suggest, to do a thing like this?

        No, none in particular. But if you want to go that route perhaps Text::Tokenizer would be a good place to start.

        Thanks for the encouragement. Hardest part with coding i find is to actually come up with an "assignment" so you can evolve.