use warnings;
use strict;
use Mojo::DOM;
my $html = <<'END_HTML';
abc
xyz
xyzijk
abc def
END_HTML
my $dom = Mojo::DOM->new->xml(1)->parse($html);
$dom->find('image alt')->grep(sub { # find all tags inside
not $_->child_nodes->grep(sub { # check whether they have content
$_->type eq 'text' || $_->type eq 'cdata'
? $_->content=~/\S/ : $_->type ne 'comment'
})->size;
})->map('remove');
print $dom;
__END__
abc
xyz
xyzijk
abc def