:) Ok, now that I better understand what you're asking, here's my regex solution. I think that this improves upon some other methods by starting with the longest and working down to the shortest, (quitting as soon as a match is found).
use strict;
use warnings;
my @array = ( "this is a string is",
"a string this is",
"tie a string together" );
my $string = join "|", @array;
my $repeat = '\|.*?\1.*?' x ( scalar(@array) - 1 );
for my $n ( reverse ( 1 .. length( $string ) ) ) {
next unless $string =~ /(.{$n}).*?$repeat/;
print $1, "\n";
last;
}
Ob-Update: This assumes the substrings don't overlap. And I've tinkered with the code to make it keep track of what the original substrings looked like. In so doing, I used the | character as a delimiter, which means it shouldn't appear in the original substrings. Thanks danger for the polite nudge. ;)
Dave
"If I had my life to live over again, I'd be a plumber." -- Albert Einstein
| [reply] [Watch: Dir/Any] [d/l] |