#!/usr/bin/perl 
use strict;
use warnings;

my @text            = ;
my $multipleinserts = 0;
my $alreadyseen     = 0;

for (my $i = 0 ; $i < $. ; $i++) {
        print $text[$i];
        if ($text[$i] =~ /pattern to insert after/ && $multipleinserts || !$alreadyseen) {
                print 1+$. .": new line here\n";
                $alreadyseen = 1;
        }
}



If the search patter appears twice then the text gets inserted after the first, or you can edit the obviously named variable to have it inserted after every occurrence. You didn't state what format the numbers take so I guessed. It shouldn't be too hard to change to suit your requirements. One caveat - it doesn't check for duplicate index values.
(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org

Profile

lovingboth: (Default)
Ian

July 2025

S M T W T F S
  12345
6 789101112
13141516171819
20212223242526
2728293031  

Most Popular Tags

Active Entries

Style Credit

Expand Cut Tags

No cut tags