my $s = do {local $/=undef; }; while( $s =~ s#(?!.*?#span2tag($1,$2)#sgei ){}; print $s; sub span2tag { my ($attr, $s) = @_; return "$s" if $attr =~ /bold/; return "$s" if $attr =~ /italic/; return "$s" if $attr =~ /underline/; return $s; } __DATA__ this is some test text for bolding, underlining and italicizing text.
#### my $s = do {local $/=undef; }; while(1){ my $matched = 0; $matched ||= $s =~ s#(?!.*?#$1#sgi; $matched ||= $s =~ s#(?!.*?#$1#sgi; $matched ||= $s =~ s#(?!.*?#$1#sgi; last unless $matched; }