use AnyEvent::XMPP::Ext::MUC; sub retr_connected_users { my @data = map { chomp; s/@.*//; $_ } (`some command`); return @data; } $muc->reg_cb( message => sub { my ( undef, undef, $msg ) = @_; my @inter = retr_connected_users(); foreach my $user(@inter){ AnyEvent::XMPP::IM::Message->new ( body => construct_body($msg->body, $from), to => "$user\@" . HOST, type => "chat", )->send($conn); } }, );