use strict; use warnings; my $str="1 2 3 4 5 6 7 8 9 10"; print "string is $str\n"; $str=~s/(?<=(\d\s){1})\d*/I am replaced/; print "string is $str"; #### $str=~s/(?<=(\d\s){0})\d*/I am replaced/;