in reply to Extract a specific number of words from a string

Essentially the same as 1nickt's approach, except the regex for a word is defined in one place so you can play with it until you get it right, and matches are extracted to an array:

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my $str = 'mary had a little lamb'; ;; my $word = qr{ [[:alpha:]]+ }xms; ;; my @words = ($str =~ m{ $word }xmsg)[0 .. 2]; dd \@words; " ["mary", "had", "a"]


Give a man a fish:  <%-{-{-{-<