sub is_prefix_match { $_[0] =~ /^\Q$_\E/ && return 1 for @_[1..$#_]; 0 }

for my $str ($str1, $str2) {
  if (is_prefix_match($str, @pattern)) {
    print "$str\n";