Strings In Depth14 / 18
Up next

Match and capture

use strict;
use warnings;
use feature 'say';

my $date = "2026-09-23";
# parentheses capture into $1, $2, $3
if ($date =~ /(\d{4})-(\d{2})-(\d{2})/) {
    say "year $1 month $2 day $3";
}
What you're solving

regex groups fill $1, $2