Most languages will have literals that can be used to easily represent HTML data:
[a => {href=>url, name=>'next'}, 'Go to the', [i => 'next'], 'element']; # perl5
[a => {:href(url), :name<next>}, 'Go to the', [:i<next>], 'element']; # perl6
[:a => {:href=>url, :name=>'next'}, 'Go to the', [:i => 'next'], 'element'] # ruby
Your Lua example is very similar to the HTML::AsSubs CPAN module (
https://metacpan.org/module/HTML::AsSubs). Here is your example using this module:
use HTML::AsSubs;
sub url { 'http://www.anythingfornow.com' }
my $h = html(
a( {href=>url, name=>'next'},
'Go to the',
i('next'),
'element',
),
);
say $h->as_HTML;