in reply to Regular Expressions with varialbe with "[]"

In regular expressions, [1] is a character class matching the character 1. To prevent the string from interpretation, use \Q:
if (/\.([0-9a-z_]*?) \(.*?\Q$port_name\E .*?,/) {
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ