I was writing a file parser in Perl, so had to loop through file. File consists of fixed length records and I wanted to make a separate function that parses given record and cal
The perl optimizer is constant-folding the sprintf calls in your sample code.
sprintf
You can deparse it to see it happening:
$ perl -MO=Deparse sample.pl foreach $_ (1 .. 10000000) { $a = &get_string(); } sub get_string { return "abc\n"; } foreach $_ (1 .. 10000000) { $a = "abc\n"; } - syntax OK