use HTML::TreeBuilder; my $row_html = '

test https://www.google.com

'; my $html = HTML::TreeBuilder->new; $html->ignore_ignorable_whitespace(0); $html->no_space_compacting(1); $html->store_comments(1); $html->parse($row_html); # i will do some modifications to HTML here my $output_html = $html->as_HTML(undef,undef,{}); print $output_html;