#!/usr/bin/perl use strict; use warnings; while () { chomp; my $o = $_; next if /\D/ || /^$/; substr $_ => -0, 0, 0 x (4 - length); $_ ++ if 50 <= substr $_ => -2, 2, ""; substr $_ => -1, 0, "."; print "$o / 1000 = $_\n"; } __DATA__ 12000 12678 5 49 50 499 500 501 12000 / 1000 = 12.0 12678 / 1000 = 12.7 5 / 1000 = 0.0 49 / 1000 = 0.0 50 / 1000 = 0.1 499 / 1000 = 0.5 500 / 1000 = 0.5 501 / 1000 = 0.5