my $out = "hello\nfoo" =~ s/o*$/O/gmr; say $out #### hellOO fOO