# perldoc > Tie::SubstrHash

---
type: CommandReference
command: Tie::SubstrHash
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `tie %hash, 'Tie::SubstrHash', $key_len, $value_len, $table_size` — Create a fixed-size hash with fixed key/value lengths
- `$hash{$key} = $value` — Store a value (must be exactly $value_len characters)
- `$val = $hash{$key}` — Retrieve a value
- `delete $hash{$key}` — Delete an entry
- `keys %hash`, `values %hash`, `each %hash` — Standard hash operations
- `exists()` is **not supported**
- Storing more than `$table_size` elements causes a fatal error
- Key and value lengths must be exactly `$key_len` and `$value_len` characters

## Name

Fixed-table-size, fixed-key-length hashing

## Synopsis

perl
require Tie::SubstrHash;

tie %myhash, 'Tie::SubstrHash', $key_len, $value_len, $table_size;
## Options

- `$key_len` — Fixed length of keys (must be constant for the lifetime of the tied hash)
- `$value_len` — Fixed length of values (must be constant)
- `$table_size` — Maximum number of key-value pairs the hash can hold

All parameters are passed to `tie()` and cannot be changed afterward.

## Examples

perl
use strict;
use warnings;
use Tie::SubstrHash;

my $key_len   = 8;
my $value_len = 20;
my $table_size = 100;

tie my %hash, 'Tie::SubstrHash', $key_len, $value_len, $table_size;

$hash{'key1'} = 'value1               ';  # must be exactly 20 chars
print $hash{'key1'};                     # outputs 'value1               '
## See Also

- [Tie::SubstrHash on perldoc](https://perldoc.perl.org/Tie::SubstrHash)
- [perltie](https://perldoc.perl.org/perltie) — introduction to tie
- [Tie::Hash](https://perldoc.perl.org/Tie::Hash) — base class for tied hashes