use threads; use Thread::Queue; use xml::simple; use communication_client; my $com = communication_client->new(40000); #DST port my $thr = threads->create(sub{ while (my $data = $com->dequeue()) { print "Received:\n$data\n"; my $input = $xs->XMLin($data); my $ip = $input->{message}->[0]->{from}->[0]->{ip}; #WORK if ($input->{message}->[0]->{anyfieldsyouwant}->[0] eq "whatever") { #WORK } } }); $com->enqueue("INFOwhatever");