use strict; use warnings; my $cnt = 1; while (<>) { s/$/sprintf '%04d', $cnt++/e if /^\*+$/; print; }
Update: The above code functionally satisfies the OP specification. Thanks to ikegami for demonstrating several optimization techniques below.
In reply to Re: Numbering instances of a String in a file
by toolic
in thread Numbering instances of a String in a file
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |