I have figured out issue since every data element we pass to thread is copied down so queue enqueue and dequeue are not working on same queue due to which second program is not working. But i am not sure how to solve this problem ?
How did you figure that out?
See https://metacpan.org/pod/Thread::Queue#end
Use a different way to signal the end, like
$q->enqueue( [ 'capture' => 'ls -la' ] );
...
$q->enqueue( [ 'exit' ] );
...
while ((my $jackson = $q->dequeue()))
my( $action, @args ) = @$jackson;
last if $action eq 'exit';
if( $action eq 'capture' ){
my $result ... @args ...
|