in reply to How to repeat a string multiple times if found match
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11129359 use warnings; use Path::Tiny; my $path = path( 'test3.txt' ); $path->spew(<<END); hello world foo_ foo abc def END $path->edit_lines( sub { s/^(?=(foo_))/join '', map "$1$_\n", 1..3/e } +); print $path->slurp;
Outputs:
hello world foo_1 foo_2 foo_3 foo_ foo abc def
|
|---|