Filling of single-walled carbon nanotubes (SWCNTs) and extraction of the encapsulated species from their cavities are perspective treatments for tuning the functional properties of SWCNT-based materials. Here, we have investigated sulfur-modified SWCNTs synthesized by the ampoule method. The morphology and chemical states of carbon and sulfur were analyzed by transmission electron microscopy, Raman scattering, thermogravimetric analysis, X-ray photoelectron and near-edge X-ray absorption fine structure spectroscopies. Successful encapsulation of sulfur inside SWCNTs cavities was demonstrated. The peculiarities of interactions of SWCNTs with encapsulated and external sulfur species were analyzed in details. In particular, the donor-acceptor interaction between encapsulated sulfur and host SWCNT is experimentally demonstrated. The sulfur-filled SWCNTs were continuously irradiated in situ with polychromatic photon beam of high intensity. Comparison of X-ray spectra of the samples before and after the treatment revealed sulfur transport from the interior to the surface of SWCNTs bundles, in particular extraction of sulfur from the SWCNT cavity. These results show that the moderate heating of filled nanotubes could be used to de-encapsulate the guest species tuning the local composition, and hence, the functional properties of SWCNT-based materials.