sub thread { my $val = shift; foreach my $x (1..10) { print "hello $x from thread $val\n"; my $delay = int rand 5; sleep $delay; } }