Reactions of 1,3-bis(bromopentyl)-5(6)-substituted uracyls with a series of five-membered heterocycles containing in the ring N, S, or O atoms and a mercapto group as a substituent at the carbon atom of the ring afforded uracyl derivatives of acyclic and macrocyclic structure with 2-thiobenzoxazole, 2-thio-5-methyl-1,3,4-thiadiazole, 2-thiobenzimidazole, and 2,5-dithio-1,3,4-thiadiazole fragments. N atoms of benzoxazole and imidazole fragments of compounds obtained undergo alkylation and quaternization with alkyl iodides and alkyl tosylates.