Assuming the end of a paragraph is indicated by an empty line or --in other words-- "\n\n", you can set the special variable $/ to "\n\n" and then each iteration of <filehandle> will read a whole paragraph. Stop reading when you have reached the target paragraph

Next you split that paragraph on "\n" to get each line and the you split each line on \s (whitespace) to get each word.

use Modern::Perl; use Data::Dump qw/dump/; my $paragraph; { local $/ = "\n\n"; $paragraph = <DATA> for 1 .. 3; # we need the third paragraph } my @words; push @words, map {[split /\s/]} split /\n/, $paragraph; say dump(@words); __DATA__ This is the start of the first paragraph. This is the second line of this first paragraph. And this is the last line of it. Here starts the second paragraph. This is the second line of this second paragraph. And this is the last line of it. Here starts the third paragraph. This is the second line of this third paragraph. And this is the last line of it. Here starts the fourth paragraph. This is the second line of this fourth paragraph. And this is the last line of it.
Output:
( ["Here", "starts", "the", "third", "paragraph."], [ "This", "is", "the", "second", "line", "of", "this", "third", "paragraph.", ], ["And", "this", "is", "the", "last", "line", "of", "it."], )
Update: added an example program.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: how to read a particular paragraph from middle of a file line by line and enter each string in the line as an element of an array by CountZero
in thread how to read a particular paragraph from middle of a file line by line and enter each string in the line as an element of an array by rockstar99

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.