my @pipe_handles = \( $from_parent_one, $to_child_one, $from_child_one, $to_parent_one, $from_parent_two, $to_child_two, $from_child_two, $to_parent_two ); ... foreach my $handle ( @pipe_handles ) { close( $$handle ) if defined openhandle( $$handle ); }