#!/usr/bin/perl -w use strict; my $dat = 'size="10">20iliX 234bvc 234yyyyy size="10">35iliX'; $dat =~ s/size="10">(\d{1,2})iliX/size="10" text-anchor="end">$1iliX/g; print $dat; #size="10" text-anchor="end">20iliX 234bvc 234yyyyy size="10" text-anchor="end">35iliX