As others have remarked, I find the problem statement confusing. (In particular, these tired, old optics would have appreciated less eye-bezoggling example strings!) However, a couple of code examples that might help to define the problem:
>perl -wMstrict -le
"my $big = 'xyzzyABCDfoobar';
my $small = 'ABCD';
;;
(my $padded = $big) =~
s{ \A (.*?) (\Q$small\E) (.*) }
{ 'o' x length($1) . $2 . 'i' x length($3) }xmse
or die 'small substring not found';
print qq{'$big'};
print qq{'$padded'};
;;
$padded = '';
my $is = index $big, $small;
die 'small substring not found' if $is < 0;
my $op = $is;
my $ip = length($big) - length($small) - $op;
$padded = 'o' x $op . $small . 'i' x $ip;
print qq{'$big'};
print qq{'$padded'};
"
'xyzzyABCDfoobar'
'oooooABCDiiiiii'
'xyzzyABCDfoobar'
'oooooABCDiiiiii'
Update: Added die on substitution failure in substitution example.