in reply to Callbacks in async code

You seem to be confused about the order of execution here:

... my $return_code; my $cb = sub { my $ret_val = shift; $return_code = $ret_val; }; add_route($ip_address, $next_hop, $cb); print $return_code; #post_job_process($return_code, $file_name); ...

add_route() will basically return immediately, and you print out $return_code immediately. What you seem to want is to print out $return_code in your callback instead.

As an alternative to printing in the callback, you might want to ->send the return code using a condvar, and ->recv that somewhere up the call stack where you actually need it.