(b) Where the inmate is permitted in accordance with any other law to proceed with the action or proceeding as a poor person the expense of transporting the inmate to, or lodging or guarding him at any place other than in a state correctional institution or any other expense relating thereto shall be a state charge; provided, however, that where an inmate has been granted such permission and a recovery by judgment or by settlement is had in his favor, the court may direct him to pay out of the recovery all or part of any sum expended by the state.