use Interpolation '%:$$->$' => sub {sprintf '%'.$_[0], $_[1]}; my $x = 41.758; my $name = "Jenda"; print "Hello $%{'06d'}{$x} or $%{' 10.5f'}{$x}, $%{'20s'}{$name}, and so forth\n"; $x = 1.7; $name = "Leaveolus"; print "Hello $%{'06d'}{$x} or $%{' 10.5f'}{$x}, $%{'20s'}{$name}, and so forth\n"; #### use Interpolation 'S' => sub { local $_ = sprintf("%.2f", shift()); 1 while s/^(-?\d+)(\d{3})/$1,$2/; '$'.$_; }; #... print "And the total price is $S{$Price}.\n";