in reply to Reg exp with ansi

The value of an interpolated variable in a regex is not supposed to be escaped automatically; it would be impossible to use strings as regexes that way. Instead, you can ask for the escaping when you need it, with quotemeta or \Q: unless ($line =~ /\r\n\Q$prompt\E$/) {