sub handle_foo { my $message= 'Example'; my $callback= sub { print $message; }; ... }; #### sub fetch_item { my( $item, $on_success )= @_; my $fetch; $fetch= sub { http_get( $item, success => $on_success, error => sub { if( can_retry( $item ) ) { goto &$fetch; }; }, }; }; #### sub fetch_item { my( $item, $on_success )= @_; my $fetch; $fetch= sub { http_get( $item, success => sub { undef $fetch; # we are done goto &$on_success; }; error => sub { if( can_retry( $item ) ) { goto &$fetch; } else { undef $fetch; # we are done retrying }; }, }; };