my $answer; eval { $answer = ($str =~ $pattern); 1 } or warn "Error in the pattern: $@";