sub repeated_substring {
  my($str) = @_;
  my $substr = '';

  my $pos = 0;  while ($pos <= length($str) - 2) {
    pos($str) = $pos;

    if ($str =~ /((.{@{[ 1 + length $substr ]},}).*\2)/sgc) {
      $substr = $2;
      $pos = pos($str) - length($1) + 1;
    } else {
      $pos++;
    }
  }

  return $substr;
}

__END__
Of course, that gets ridiculously slow, because of all the backtracking.


Ronald
