# handle 5 in the thousandth's place with nothing or zeros following $pete =~ s/( # substitute, start capture $1 \d* # none or more digits \. # a decimal point \d # tenths digit (\d) # capture hundredths digit as $2 ) # end capture $1 50*$ # digit 5 followed by none or more 0's to the end /1&$2 ? $1+.01 : $1/xe; # then do as you had $rooker = sprintf "%.2f", $pete;