my $x = qq(1st line\n2nd line\n3rd line\n); (my $y = $x) =~ s/^\d/_/g; # useless use of /g print qq("$y"); # output:"_st line\n2nd line\n3rd line\n" *) ($y = $x) =~ s/^\d/_/mg; print qq("$y"); # output:"_st line\n_nd line\n_rd line\n" ($y = $x) =~ s/.\d/_/sg; print qq("$y"); # output:"1st line_nd line_rd line\n" ($y = $x) =~ s/.\d/_/smg; # useless use of /m print qq("$y"); # output:"1st line_nd line_rd line\n"