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


in reply to Re: Concatenating strings with different length
in thread Concatenating strings with different length

Or even:
#!/usr/bin/perl use warnings; use strict; #use Data::Dumper; my %fragments; while ( my $line = <DATA> ) { chomp $line; my @words = split / /, $line; for my $i (0 .. $#words - 1) { push @{ $fragments{$words[$i]} }, join ' ', @words[0 .. $i-1, $i+1 .. $#words]; } } for my $term ( keys %fragments ) { print "There are $term " . ( join ' and ', @{ $fragments{$term} } +) . ".\n"; } __DATA__ big businesses fast red cars big smart companies fast light planes fast animals big bad wolves small bad girls bad growling bears
Output:
There are small bad girls. There are light fast planes. There are growling bad bears. There are bad big wolves and small girls and growling bears. There are big businesses and smart companies and bad wolves. There are smart big companies. There are red fast cars. There are fast red cars and light planes and animals.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ