use strict;
my $str = ' Есть текст и много строк
В тексте встречаются $s1 $s2 $s3 $s4 $c1 $c2 $c4
В каждой строке есть хоть 1 такой текст, могут быть и 2 и 3 в 1 строке, но без дублей.
Найти я смог их так (\\$s\\d)|(\\$c\\d) и удалить могу их всех, но как удалить все кроме них не понял.
Заранее спасибо за ответ! ';
my $regex = qr/.*?($|\$[sc]\d)/mp;
my $subst = '$1';
my $result = $str =~ s/$regex/$subst/rg;
print "The result of the substitution is' $result\n";
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html