This is stocked mainly for re-sealing portlights.
What you do is get a length of the right section, stick the ends togethre to form a loop, and then using a few drops of glue stick the loop in place.
For older portholes we have found that using a round section is a good idea, even if the original was rectangular. This is because it compresses progressively, so absorbing the odd misalignments in the old porthole.
Generally it is not a good plan to usr soft foam rubber, it only works for a short time.