in reply to substr and strings on the outside

I'm not sure this does what you want in all cases, but it might be a step forward:
my $f = " "; substr($f, length $f, length $f, "12345");
Or do you want the new string to go in at exactly position 5, even if the old string is shorter than that? Then:
my $f = " "; my $l = length $f; substr($f, $l, $l, " " x ($l<5 ? 5-$l : 0) . "12345");
Having said that, this all may betray my failure to understand the question, since one could get the same result with
$f . " " x ($l<5 ? 5-$l : 0) . "12345".

§ George Sherston