Instead of split on + and rejoin with space, you could use a regex for that. The split already has some regex overhead.
use warnings; use strict; my @tests = ("this is+ +test", "this+test", "morepluses+++++++test"); for (@tests) { s/\++/ /g; #multiple+ to single space (see note) print "$_\n"; } __END__ this is test this test morepluses test or could use this regex to also compress spaces: s/[\s\+]+/ /g; #multiple spaces or + to single space this is test this test morepluses test
Note: in /\++/ the first + is escaped to mean a literal + sign, the second plus is a "quantifier command" to the regex engine, meaning "one or more". Your split error arises because of this second meaning and there is nothing before the + to "quantify".

Update: If you just want to convert each + to a space. tr will run much faster at that job because it builds a simple translation table. It does not use a regex, so the + should not be escaped:

use warnings; use strict; my @tests = ("this is+ +test", "this+test", "morepluses+++++++test"); for (@tests) { tr /+/ /; #lower overhead than the regex engine print "$_\n"; } __END__ this is test this test morepluses test

In reply to Re: RegExp error PLEASE HELP! by Marshall
in thread RegExp error PLEASE HELP! by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.