# perldoc > Tie::Hash::NamedCapture

---
type: CommandReference
command: Tie::Hash::NamedCapture
mode: perldoc
section: 
source: perldoc
---

## Quick Reference

- `tie %hash, 'Tie::Hash::NamedCapture'` — create hash behaving like `%+` (leftmost defined capture buffer)
- `tie %hash, 'Tie::Hash::NamedCapture', all => 1` — create hash behaving like `%-` (array refs of all capture buffers with that name)
- `%+` — tied hash of named captures (only defined buffers)
- `%-` — tied hash of named captures (all buffer names, including undef entries)

## Name

**Tie::Hash::NamedCapture** — Named regexp capture buffers (implements `%+` and `%-` special hashes)

## Synopsis

perl
tie my %hash, "Tie::Hash::NamedCapture";
# %hash now behaves like %+

tie my %hash, "Tie::Hash::NamedCapture", all => 1;
# %hash now accesses buffers from regexp in $qr like %-
## Description

This module implements the special hashes `%+` and `%-`.  
It can tie other variables using the same mechanism.

**Without `all`** (or `all` false): tied hash elements are the contents of the leftmost defined buffer with the key name. Behaves like `%+` — keys are only names of buffers that captured (defined values).

**With `all => 1`**: tied hash elements are array refs listing the contents of each capture buffer whose name is the same as the key. If none of those buffers were involved in the match, the array ref contains as many `undef` values as there are capture buffers with that name. Behaves like `%-` — keys correspond to all buffer names found in the regex.

This implementation has been moved into the core executable; this module is loaded only for backward compatibility.

## Options

- `all => 1` — When tied, the hash behaves like `%-` (array of all captures for each named buffer). When omitted or false, behaves like `%+` (single leftmost defined capture).

## See Also

- `perlreapi` (perldoc.perl.org/perlreapi)
- `re` (perldoc.perl.org/re)
- "Pragmatic Modules" in `perlmodlib` (perldoc.perl.org/perlmodlib)
- `%+` in `perlvar` (perldoc.perl.org/perlvar)
- `%-` in `perlvar` (perldoc.perl.org/perlvar)