# Perl Patterns

> Use when modern Perl 5.36+ idioms, best practices, and conventions for building robust, maintainable Perl applications. Only for Perl — not for other languages. Triggers on "perl-patterns", "perl patterns", "patterns".

- Skill: `majinmagros/perl-patterns` (Agent Skill, multi-file: 9 files)
- Install (CLI): `npx get-skill add majinmagros/perl-patterns`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majinmagros/perl-patterns/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majinmagros (https://skillmd.com/u/majinmagros)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/majinmagros/perl-patterns

---


# Modern Perl Development Patterns

Idiomatic Perl 5.36+ patterns and best practices for building robust, maintainable applications.

## When to Activate

- Writing new Perl code or modules
- Reviewing Perl code for idiom compliance
- Refactoring legacy Perl to modern standards
- Designing Perl module architecture
- Migrating pre-5.36 code to modern Perl

## When NOT to Use

- Other languages (use `python-patterns`, `golang-patterns`, etc.)
- Perl security review specifically (use `perl-security`)

## How It Works

Apply these patterns as a bias toward modern Perl 5.36+ defaults: signatures, explicit modules, focused error handling, and testable boundaries. The examples below are meant to be copied as starting points, then tightened for the actual app, dependency stack, and deployment model in front of you.

## Contents

| Topic | Reference |
|---|---|
| Core principles (pragma, signatures, context, deref, `isa`) | `references/core-principles.md` |
| Error handling (eval/die, Try::Tiny, try/catch) | `references/error-handling.md` |
| Modern OO (Moo, roles, native class) | `references/modern-oo.md` |
| Regular expressions | `references/regex.md` |
| Data structures and references | `references/data-structures.md` |
| File I/O (three-arg open, Path::Tiny) | `references/file-io.md` |
| Module organization and Exporter | `references/modules.md` |
| Tooling (perltidy, perlcritic, carton) | `references/tooling.md` |

## Quick Reference: Modern Perl Idioms

| Legacy Pattern | Modern Replacement |
|---|---|
| `use strict; use warnings;` | `use v5.36;` |
| `my ($x, $y) = @_;` | `sub foo($x, $y) { ... }` |
| `@{ $ref }` | `$ref->@*` |
| `%{ $ref }` | `$ref->%*` |
| `open FH, "< $file"` | `open my $fh, '<:encoding(UTF-8)', $file` |
| `blessed hashref` | `Moo` class with types |
| `$1, $2, $3` | `$+{name}` (named captures) |
| `eval { }; if ($@)` | `Try::Tiny` or native `try/catch` (5.40+) |
| `BEGIN { require Exporter; }` | `use Exporter 'import';` |
| Manual file ops | `Path::Tiny` |
| `blessed($o) && $o->isa('X')` | `$o isa 'X'` (5.32+) |
| `builtin::true / false` | `use builtin 'true', 'false';` (5.36+, experimental) |

## Anti-Patterns

```perl
# 1. Two-arg open (security risk)
open FH, $filename;                     # NEVER

# 2. Indirect object syntax (ambiguous parsing)
