in reply to retrieving the absolute url

First, the comments in this block say one thing, but the code says something different

# Set up a callback that collect image links my @imgs = (); my $callback = sub { my($tag, %attr) = @_; return if $tag ne 'a'; # we only look closer at <img ...> push(@imgs, values %attr); };

You probably want to change this to:

return if $tag ne 'img'; push(@imgs, $attr{'src'});
or
return if $tag ne 'a'; push(@imgs, $attr{'href'});

Otherwise, if there are other attributes in the tag (alt=, border=) then you may end up getting their values instead.

Also, the abs() method to URI::URL returns a URI::URL object, so you'll need to change this line:

@imgs = map { $_ = url($_, $base)->abs; } @imgs;
to this:
@imgs = map { $_ = url($_, $base)->abs->as_string; } @imgs;

Which will give you a string, that can be used instead. For some reason this only fails occasionally, so this may be the problem that you are running into.