perl -pi.bak -e 's/(?<=weak(?:){6})(?=strong)/insert($1)/eig; BEGIN { sub insert { my $name = shift; return "value 8, value 9, value 10"; } }' *.html