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.