in reply to Search string giving incorrect results

I can't say much without having examples of data which produce these "erronious results," but I've two guesses:

  1. $in{for} is empty. This means that the regex is using whatever the last successful match or replacement was. This is probably not what you want. Postfix $in{for} with .* to avoid this.
  2. $in{for} contains metacharacters. That is, things like . and * which have special meaning to a regular expression. To get around this, use \Q$in{for}\E instead of $in{for} in the regex; or, somewhere above the regex, run $in{for} through quotemeta.

perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'