note
tobyink
<blockquote><p><i>The first comma was removed from each number.</i></p></blockquote>
<p>The <c>s///</c> operator by default removes only the first match. So:</p>
<code>
my $var = "foobarfoobaz";
$var =~ s/foo//;
say $var; # says "barfoobaz"
</code>
<p>There are various flags you can include to alter its default behaviour though. One of the most useful is the "g" (global) flag...</p>
<code>
my $var = "foobarfoobaz";
$var =~ s/foo//g;
say $var; # says "barbaz"
</code>
<p>Note that the slashes may be replaced with other characters, so you could equally write:</p>
<code>
my $var = "foobarfoobaz";
$var =~ s@foo@@g;
say $var; # says "barbaz"
</code>
<p>Or even:</p>
<code>
my $var = "foobarfoobaz";
$var =~ s{foo}{}g;
say $var; # says "barbaz"
</code>
<p>... which some people might find more readable. Though note that there are a handful of characters (hash, question mark and single quote spring to mind) that trigger special behaviours here ([mod://perlop] has more details).</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-757127">
<small><small>
<tt>perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
</tt></small></small>
</div></div>
961908
961918