if (substr ($str1, $pos) =~ /^\Q$str2/) { ... } # or if (substr ($str1, $pos, length $str2) eq $str2) { ... }