I see you are new to our Monastery: so let me bid you welcome and may your search for more Perl-wisdom be fruitful.

It is the custom in our Monastery that you show the code you have written to solve your problem or otherwise show us that you have at least tried to solve the problem. The Monastery is not a "Solve-my-homework-for-me"-service!

That being said, did you try to use the m// function? It tries to match a regular expression against another string and returns true if the match succeed:

use strict; my $text='Try to find the hidden string here!'; if ($text=~m/\bhidden\b/) { print "We found the hidden string!\n"; } else { print "No match, sorry.\n"; }
Some explanation:Now for the other part of your question: What other word do you need to grab? Do you know what that word will be beforehand or is it just any word before or after the first word you found? Why do you want to analyse it character-by-character? That seems a bit artificial.

Update: as japhy and ysth told me, the marker for the word boundary is \b. I have updated the example program above. What do we learn from such errors: Never try to do any serious work before your second cup of strong tea!

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law


In reply to Re: Find a specific word in a text file by CountZero
in thread Find a specific word in a text file by algonquin

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.