in reply to Regex problem

If I understand your question correctly, the problem isn't with your s///, it's with your initialisation of $value. It should be single-quoted, not double.
my $value = 'sample1\*sample2\*sample3*sample4*sample5'; $value =~ s#\*#STAR#g; print $value

Output:

sample1\STARsample2\STARsample3STARsample4STARsample5

Replies are listed 'Best First'.
Re^2: Regex problem
by roboticus (Chancellor) on Aug 02, 2007 at 23:13 UTC
    FunkyMonk:

    I think you meant:

    my $value = 'sample1\\*sample2\\*sample3\\*sample4\\*sample5'; print $value,"\n"; $value =~ s#\\\*#STAR#g; print $value,"\n";

    as the \ is a special character and needs to be quoted in strings and regexes. The * is special in the regex and also needs quoting.

    ...roboticus

    UPDATE: ikegami just pointed out to me that I am a doofus incorrect, as demonstrated:

    my $value = 'sample1\\*sample2\\*sample3\\*sample4\\*sample5'; my $value2 = 'sample1\*sample2\*sample3\*sample4\*sample5'; if ($value eq $value2) { print "I am a studly programmer\n"; } else { print "I am a doofus\n"; }

      In single-quoted literals, escaping \ is optional if it's not followed by \ or the string delimiter.

      $x = 'a\b'; print("$x\n"); $x = 'a\\b'; print("$x\n");
      a\b a\b