Try playing with this:

use strict; use warnings; use feature 'say'; for my $string (<DATA>) { chomp $string; if ( $string =~ / (?<!_) _ ([a-zA-Z]+) $ /x ) { say "Found $1 in $string"; } else { say "No match in $string"; } } __DATA__ He_is_super_hero_Spiderman He_was_a_super_actor_Tom He_was_a_ He_was_a_42 That_nansh_he_was_a_right__one

Besides reading perlretut as suggested by the Anonymous One, you should consider what you are really trying to do here. If your strings really look like this, it indicates that you are doing some awkward text munging with split and join to get to this point. There is almost certainly a better way to do it. You may be suffering from the XY Problem syndrome. You should state what your overall objective is, instead of throwing out these snippets one at a time.


The way forward always starts with a minimal test.

In reply to Re: Pattern for a single word by 1nickt
in thread Pattern for a single word by Nansh

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.