Several good ways to do this have already been mentioned for Perl 5.
I'll also note that your question was one of the many things addressed in Perl6.
Perl 6 added an explicit phaser for first loop invocation you can use like this:
for @arr -> $line { FIRST { print ' ' xx $indentation }; say $line; }
In reply to Re: Easiest way to do something only on first iteration of loop
by ctilmes
in thread Easiest way to do something only on first iteration of loop
by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |