our $ALREADY_CONNECTED = 0; # this var's purpose is called a semaphore DOCUMENT: for my $document (@collection) { if (!$ALREADY_CONNECTED) { open2(...); # and save the handles for later usage $ALREADY_CONNECTED = 1; # whoa! magic! redo DOCUMENT; } else { # blah blah process $document here, # the in/out handles exist. }; };