Branching Directives: if, unless, else, elsif

Learn about branching directives in Perl.

Control flow directives

Perl’s basic control flow is straightforward. Program execution starts at the beginning (the first line of the file executed) and continues to the end:

Press + to interact
say 'At start';
say 'In middle';
say 'At end';

Perl’s control flow directives change the order of what happens next in the program.

Branching directives

Branching directives in Perl are explained below:

Branching directives in Perl

The if directive

The if directive performs the associated action only when its conditional expression evaluates to a true value: ...

Get hands-on with 1400+ tech skills courses.