CORE(3perl)

✨ NAME ✨

CORE β€” the namespace where Perl's core routines live, and yes bestie it's giving main character energy πŸ’…


🌸 SYNOPSIS 🌸

BEGIN {
    *CORE::GLOBAL::hex = sub { 1; };
}

print hex("0x50"),"\n";                     # prints 1
print CORE::hex("0x50"),"\n";               # prints 80
CORE::say "yes";                            # prints yes

BEGIN { *shove = \&CORE::push; }
shove @array, 1,2,3;                        # pushes on to @array

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the CORE namespace is basically your backstage pass πŸŽ€ to Perl's original built-in functions. The CORE package is baked right into Perl itself, so bestie you literally do not need to use or require some hypothetical CORE module before you can reach in and grab routines from this namespace. it's already there. no cap. ✨

wanna know which functions are built in? the full list lives over in perlfunc πŸ“–

so here's the tea for all Perl keywords: if you slap a CORE:: prefix on the front, it forces the built-in function to be used β€” even if it's been overridden, or even if it would normally need the feature pragma. 🫢 And like… despite how it looks? this has absolutely nothing to do with the CORE package. it's part of Perl's syntax. iykyk πŸ’€

For many Perl functions, the CORE package actually contains real subroutines. this feature is new in Perl 5.16 ⭐ You can take references to these and make aliases, which is lowkey iconic. These subroutines exist for all keywords except the following πŸ‘‡

  • __DATA__, __END__, and, cmp, default, do, dump, else, elsif, eq, eval, for, foreach, format, ge, given, goto, grep, gt, if, last, le, local, lt, m, map, my, ne, next, no, or, our, package, print, printf, q, qq, qr, qw, qx, redo, require, return, s, say, sort, state, sub, tr, unless, until, use, when, while, x, xor, y
mind the gap bestie πŸ’€ that's the whole list, don't come for me.

However πŸ™ˆ some CORE subroutines can only be aliased and called as barewords. that means no ampersand syntax (&foo) and no calling them through references β€” periodt. peep the shove example up in the SYNOPSIS for the vibe. These are:

  • __CLASS__, chomp, chop, defined, delete, eof, exec, exists, lstat, split, stat, system, truncate, unlink

and why are they like this? because they have special syntax that can't always be translated into a simple list (like, eof versus eof(), hello 😭) or they have other special behavior. it's just built different, fr fr.


πŸ‘‘ OVERRIDING CORE FUNCTIONS πŸ‘‘

so you wanna replace a Perl built-in with your own version? obsessed. πŸ’– To do that, you need to import it at compile-time. the convenient way to pull this off is with the subs pragma ✨ and heads up β€” this will only affect the package where you imported that subroutine. just that one. no crossover:

use subs 'chdir';
sub chdir { ... }
chdir $somewhere;

now, if you want to override a built-in globally (as in, across all namespaces, main character on every stage πŸ’…), you need to import your function into the CORE::GLOBAL pseudo-namespace at compile time:

BEGIN {
    *CORE::GLOBAL::hex = sub {
        # ... your code here
    };
}

and then your shiny new routine gets called whenever a built-in function is called without a qualifying package:

print hex("0x50"),"\n";                     # prints 1

in both of those cases, if you still wanna reach the original, unaltered routine? just use the CORE:: prefix and boom 🌈:

print CORE::hex("0x50"),"\n";               # prints 80

πŸŽ€ AUTHOR πŸŽ€

This documentation provided by Tels <nospam-abuse@bloodgate.com> 2007.


🌟 SEE ALSO 🌟

perlsub, perlfunc.


and that's the whole vibe check, bestie 🧚 go forth and slay those built-ins πŸ’œ

this page was served fresh by perl v5.44.0, dated 2026-10-17 β€” yes she ate, and yes she knows it πŸ’…βœ¨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms