sub convert_to_float { my ( $number ) = @_; $number = sprintf '%.02f', $number || 0; $number =~ s/.(\d*[1-9])?0*\z/,$1/; return $number; } convert_to_float(1); __END__ Use of uninitialized value $1 in concatenation (.) or string