#!/usr/bin/perl use threads; use IO::Uncompress::Gunzip; use IO::Compress::Gzip; my $testfile = 'test.gz'; # create compressed file my $fh = new IO::Compress::Gzip($testfile); print {$fh} "$_ qwertyuiopasdfghjklzxcvbnm\n" foreach(1..5000); close($fh); print "$testfile created\n"; # read compressed file, starting a thread for every 500 lines $fh = new IO::Uncompress::Gunzip($testfile); my @chunk = (); while(my $line = <$fh>) { push(@chunk,$line); if(scalar(@chunk) == 500) { my $th = threads->create(\&test,\@chunk); @chunk = (); $th->join(); } } my $th = threads->create(\&test,\@chunk); $th->join(); close($fh); sub test { my ($lines) = @_; print foreach(@$lines); }