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

Hi Monks

I want to divide a list of strings into substrings. Following rules should be met:

* It must be able to set together each string with a set of substrings.

* The length of each substring should be at least 3 characters.

* The length ($len) of all substrings added together (+2 penalty for each substring) should be as small as possible.

An example: The list @list should give as result e.g. the list of substrings @expected_substrings. The length $len gives for this example 46.

my @list=("set abcde-efghi 12345", "set abcde-ijkl 12345", "clr abcde-efghi+123", "clr abcde-ijkl 12345"); my @expected_substrings=("set","clr"," abcde-","efghi", "ijkl"," 12345","+123"); my $len=@expected_substrings*2; $len+=length($_) foreach @expected_substrings;
Do you have any brilliant idea how to solve this without using long loops with many trials?

Many Thanks