use strict; =pod ...if either revenue(s), sales or growth occur within three words of the word currency or the phrase "foreign exchange." =cut my @sources = ('foreign exchange','currency'); my $sourceData = <$_} qw|revenue sales growth|; my $cntFound = 0; for (@sources) { while($sourceData=~m/$_\s+(\w+)\s*(\w+)?\s*(\w+)?\s*/g) #does the word appear? { # is anything in the searchvector in the found words? for ($1,$2,$3) { my $r = $_; $r=~s/revenues/revenue/; if($searchvector{$r}){++$cntFound}; } } } print qq|Total times search (| . (join ' ', (values %searchvector)) . ') found: ' . $cntFound . qq|\n|; 1; #### Total times search (growth sales revenue) found: 6