find longest substring for given word