$str= 'no change not these '; $str =~ s{(<[^>]*?>)} { my $x=$1; $x=~s/ /_/g; $x; }egx; print $str