#!/usr/bin/perl -w use warnings; use strict; use IO::Socket::Multicast; use threads; use threads::shared; my $thread1 = threads->create(\&MulticastListen, '192.168.0.1'); $thread1->detach(); my $thread2 = threads->create(\&MulticastListen, '192.168.1.1'); $thread2->detach(); while (1) { # Some codes here } ################# ## Subroutines ## ################# sub MulticastListen { my $interfaceIP = shift; my $Socket = IO::Socket::Multicast->new( LocalPort => '12345', LocalAddr => '224.10.10.10', ReuseAddr => 1 ); $Socket->mcast_add('224.10.10.10', $interfaceIP ); while (1) { $Socket->recv( $Data, 1024 ); print "[$Data]\n"; } }