Here is a fun (and powerful) way to only do some substitutions:
Though I'd probably use one of the other solutions mentioned in this particular case. - tye (but my friends call me "Tye")my $str= "1_abc/2_def/bla_30_31_blah"; my $count= 0; while( $str =~ /\d+_/g ) { last if 2 < ++$count; $str =~ s///; } print "\$str=($str)\n"; # $str=(abc/def/bla_30_31_blah)
In reply to (tye)Re: changing only the first two matches of a regex
by tye
in thread changing only the first two matches of a regex
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |