http://www.perlmonks.org?node_id=482475

themage has asked for the wisdom of the Perl Monks concerning the following question:

Hi Enlighted Ones,

I'm here looking for wisdom from you. I have an expression, and I need the expressions contained in that. For example, if I have:
camel perl book
I would like to get:
camel perl book camel perl perl book camel perl book
I made this small sub that returns the pretended list, but I would like to know your opinions on that:

sub list { my $words=shift; chomp $words; my @words=split /\s/, $words; my @longs=(); for my $i (1..$#words-1) { push @longs, map { join " ", @words[$_..$_+$i]} (0..$#words-$i); } push @words, @longs,$words; return @words; }
This is intented to create a query for a payperview search engine, where the records which search expression is complete in the query will be shown.

There is any better way to do this?

Thank you very much for sharing your wisdom.