#!/usr/bin/perl -w use Thread; use Thread::Semaphore; my $max_parallel_jobs = 3; my $users_file = "users.txt"; open(USERS, "<$users_file") or die "Could not read $users_file!\n"; my @users = ; close(USERS); my $total_jobs = $#users; my $sem = Thread::Semaphore->new($max_parallel_jobs); my @output=(); for my $job (0..$total_jobs){ $sem->down(); my $thread = Thread->new(\&test_user, $users[$job]); $thread->join(); } while(<@output>){ print "output: $_"; } sub test_user { chomp($_[0]); print "USER: $_[0]\tist jetzt an der Reihe!\n"; push(@output, $_[0]); $sem->up(); }