I see two things in that code that I would suggest to improve:
- Don't use eval - it allows execution of arbitrary Perl code, and getting the quoting of interpolated code right is tricky (try entering one double quote for $str), and so it should only be used sparingly. In this case it is not needed, just say: my $answer = $str =~ /$pattern/; - however note that then, your regexes should not be entered with the surrounding slashes.
(If you do use eval someday, make sure to do proper error checking, as described e.g. here: something like eval "$code; 1" or warn "eval failed: $@";)
- my $str = <STDIN>; and $pattern will have a newline on the end, which you should chomp off, e.g. chomp( my $str = <STDIN> );. See also the Basic debugging checklist, which suggests using a module like Data::Dumper or Data::Dump to look at what variables actually contain. If you use the former, I recommend setting $Data::Dumper::Useqq=1;.
In Perl, as opposed to Python's "there should be one - and preferably only one - obvious way to do it", TIMTOWTDI - There Is More Than One Way To Do It. While there are certainly 20 different ways to write the code you showed, don't worry about that too much - just keep your eye out for best practices like the ones I mentioned above, and otherwise enjoy learning Perl :-) We'll be happy to help.
Made a few minor edits.