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