sub repeated_substring {
    my $string = "@_" ;
    my ($strlen, $i, $len, $limit, $sub) ;
    $strlen = length($string) ;
    for ( $len=int($strlen/2) ; $len>=2 ; $len-- ) {
	my %repeated ;
	$limit = $strlen - $len ;
	for $i ( 0 .. $limit ) {
	    next if ($i < $len and $i > $limit - $len) ; ## Skip substrings of length $len that can't be matched
	    $sub = substr($string, $i, $len) ;
	    return $sub if (defined($repeated{$sub}) and ($i - $repeated{$sub} >= $len)) ; ## Only return non-overlaping substr
	    $repeated{$sub} = $i ;
	}
    }
}
