sub repeated_string {
	$str = shift;
	$longest = "";
	
	return "" unless $str =~ /(.).*\1/;
	$off = 0;
	$len = 1;
	
	{
		$match = substr $str, $off, $len;
		if ( ( substr $str, $off + $len ) =~ /\Q$match\E/ ){
			$longest = $match;
			$len++;
		}
		else{
			$off++;
		}
		return $longest if ( $off + $len ) >= length $str;
		redo;
	}
}
