Matching words in a sentence?
22:32 08 Dec 2011

I want to extract words between two words using Perl, but I don't know if can use regular expressions or any library to do that.

Example:

$sen = "A short quick brown fox jumps over the lazy dog running in the market";

@sentence = split / /, $sen;
foreach my $word (@sentence) {

}        

I want to get the words between brown and lazy together with 2 words from the left and 2 words from the right.

How can I come up with this output?

words between: fox jumps over the
2 words from left: short quick
2 words from right: dog running
perl