$newtext = "some new text"; $spantext =~ s/(\]+\>)[^<]+(<.*>)/$1${newtext}$2/i; #assuming there's no tags between the spans... #### $_='7065726c646f63207065726c7265';system pack"H*",$_