#(other program stuff here) my $a=10.5; my $str=sprintf "%.1f",$a; $str =~ s/\.(\d)$/,$1/; #only do the last . and preserve the digit print $str; #(and more program stuff here)