in reply to Subroutine does not sleep

In wait function read the parameter like: my $time = shift or my ($time) = (@_). Also, there is a perl function wait. You should name your functions differently, to avoid clashes with builtins.