#!/usr/bin/perl use strict; use warnings; local $/; local $_ = ; my $c; s/()(?{++$c;})/<$c>$1/g; print; __DATA__ fo

ba

foobar

foobar

#### <1>fo

ba

<2>foo<3>bar

foobar