longest match of proper prefix and proper suffix