Control flow

Statement modifiers

Full

Postfix if / unless / for / while — a whole control structure after the statement.

A statement modifier attaches a condition or loop to the end of a single statement — no block, no braces. It reads like English and is the idiomatic form for one-liners.

Postfix if / unless #

say "even" if 4 %% 2;
say "odd" unless 4 %% 2;
Output
even

The unless line produces nothing because 4 %% 2 is true.

Postfix for #

A trailing for runs the statement once per element, with $_ set — so the .method shorthand pairs naturally with it.

say $_ for 1..3;
.say for <a b>;
Output
1
2
3
a
b

Postfix while / until #

my $i = 0;
$i++ while $i < 3;
say $i;
Output
3

Notes #