package Day05; use strict; use warnings; use Exporter qw( import ); our @EXPORT = qw( is_nice_1 is_nice_2 ); sub is_nice_1 { my $string = shift @_; # ensure that we have at least 3 vowels return 0 unless ( ( () = $string =~ m/[aeiou]/g ) > 2 ); # check that we have a repeating character using a back reference return 0 unless ( $string =~ m/(\w)\1/ ); # check that we don't have prohibited substrings return 0 if ( $string =~ m/ab|cd|pq|xy/ ); # if we've gotten this far, we've met all 3 criteria return 1; } sub is_nice_2 { my $string = shift @_; # match a pair of any two letters ( (\w\w) ) that appears at least # twice ( \1 ) in the string without overlapping ( \w* ) return 0 unless ( $string =~ m/(\w\w)\w*\1/ ); # ensure that string contains at least one letter which repeats # with exactly one letter between them return 0 unless ( $string =~ m/(\w)\w\1/ ); # if we've gotten this far, we've met both criteria return 1; } 1;