It would really help if you could post some of the code that you currently have, so that we can see what you've tried so far. For the first part of your question, you might want to try using sprintf, something like this:
my $new_value = sprintf("%.5f", $unformatted_value);
s/old_value/$new_value/;