timeout_func($timeout, sub { myfunc($arg1, $arg2) }); sub timeout_func { my ($timeout, $coderef) = @_; ... $coderef->(); }