#!/usr/bin/env perl6 constant $DATE-MATCH = rx/^ $=(<[12]>) $=(<[0..9]>**2) $=("01"|"02"|"03"|"04"|"05"|"06"|"07"|"08"|"09"|"10"|"11"|"12") $=(<[0..3]><[0..9]>) $/; subset PossData of Str where * ~~ $DATE-MATCH; multi sub MAIN($s) is hidden-from-USAGE { say "{$s} doesn't match the valid string condition\n$*USAGE"; } #| Parse the data string format multi sub MAIN( PossData $date #= Date in the format (1/2 2000/1900), year, month, day ) { my $match = ( $date ~~ $DATE-MATCH ); my $result; { $result = Date.new( :year( $match. + ( $match. ~~ 1 ?? 2000 !! 1900 ) ), :month( $match ), :day( $match ) ); CATCH { default { say "{$date} is not a valid date\n$*USAGE"; exit; } } } say $result; }