in reply to Multiline replace regexp.

You haven't shown your expected output, but I think I understand what you're asking. I see several issues:

  1. The dot (.) loses its special meaning inside a [] character class, that is, [.] matches only a literal dot.
  2. I think what you're trying to say with [.\n] is probably that you want to match everything, since the dot . doesn't match \n by default. This is actually achieved by the /s modifier.
  3. You probably should be explicit in that you want to match starting at the beginning of the string by using the \A anchor.
  4. You may want to avoid the interpretation of any regex metacharacters in $a by using \Q...\E - see quotemeta and Mind the meta!
  5. Avoid the variable names $a and $b, as these are used by sort and may cause confusion when used elsewhere in the code.
  6. You haven't specified what would happen if the search string doesn't appear exactly once in $q.

Short, Self-Contained, Correct Example:

use warnings; use strict; my $str='qqqweqwe asdasdasd zxczxczxc tyutyutyi '; my $find='zxczxczxc'; $str=~s#\A.*\Q$find\E##s; print "<<$str>>\n"; __END__ << tyutyutyi >>

Update: Note the above isn't aware of the concept of lines at all. If you want the string 'zxczxczxc' to be matched only when it appears on a line by itself, you need to specify that.