It is possible for load_userids to return an invalid object, so always check that $u is valid. So what I'd suggest (and following conventions used in other places in the codebase):

    my $us = LJ::load_userids...
    foreach my $u ( values %$us ) { 
        next unless $u && $u->is_visible;

        $ret .= ...
    }


-- also convention, we use $u to refer to user objects.