cat test 1 2 3 4 5 perl -pe 'BEGIN{$prefix=pop;}s/(\d+)/$prefix.$1/' test A A.1 A.2 A.3 A.4 A.5