sub my_sub{ if (handle_not_valid($_[0])){ $_[0] = new_handle(); } # ... }