When the infinitive is being used as a noun these forms are almost always technically interchangeable, although the infinitive is much less common and much more formal. There are many situations where using the infinitive instead would be awkward.
The infinitive is common in proverbial language.
To err is to learn.
To live is to suffer.
These are possibly said as:
Erring is learning.
Living is suffering.
However, this would be less poetic.