#!/opt/perl/bin/perl use strict; use threads; use MCE; open my $fh, '|-', 'gzip > test.txt.gz'; foreach (1..10000) { print {$fh} sprintf("%05d%s\n", $_, ('abc123' x 10)); } close $fh; open $fh, '-|', 'gzip -cd test.txt.gz' or die "Failed to uncompress: $!\n"; $| = 1; # MCE spawns threads when threads is present MCE->new( chunk_size => 1, max_workers => 3, input_data => $fh, init_relay => 1, user_func => sub { my ($mce, $chunk_ref, $chunk_id) = @_; my $tid = threads->tid(); MCE::relay sub { print "Thread $tid ".$chunk_ref->[0]; }; } )->run; close $fh; print "\n";