use Shell; use Proc::Queue size=>5, qw(run_back); my @list = glob("*.fasta"); foreach my $list (@list) { run_back { run_code($list) } } sub run_code { my $fname = shift; my $base = ( split( /\./, $fname ) )[0]; perl("mycode.pl $base > ~/MyPerl/result_ans/$base.out"); # Tried this too, but still doesn't work # system("perl mycode.pl $base > ~/MyPerl/result_ans/$base.out"); return ; } 1 while wait != -1;