Yet another solution (without claiming efficiency over previous solutions)
#!/usr/bin/perl -wl use strict; my $str = "boy boy girl boy girl boy girl girl"; my $l = int(rand(rindex($str,"boy") - 1)); $str =~ s/^(.{$l}.*?)\bboy\b/$1man/; print $str;
In reply to Re: Randomly regex substitute
by samarzone
in thread Randomly regex substitute
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |