In your example, I think you mean to use a character class, $agent =~ /[A-Z]/. Applying that to your question, you want to use the substitution operator:

$agent = 'PerlBeginnerPerl'; $agent =~ s/([A-Z])/ $1/g;
Taking that apart, the parens store the matched character in $1. A space followed by the value of $1 is substituted. The g flag is for global, it make the substitution apply all through the string..

This will insert a leading space if the first character is capitol. To avoid that we can use a more sophisticated gadget. The additional element is a negative lookbehind assertion that we're not at the beginning of the string:

$agent =~ s/(?<!^)([A-Z])/ $1/g;

Update: (Assuming my reading of the question was correct) The second version can be converted to capture nothing by using positive lookahead for the capitol letter:

$agent =~ s/(?<!^)(?=[A-Z])/ /g;
This does the insertion by looking at the surroundings of the notch before a character, and inserting a space if conditions warrant.

After Compline,
Zaxo


In reply to Re: Search for a character in CAPS by Zaxo
in thread Search for a character in CAPS by c_lhee

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.