Perl supports many kinds of conditional statements (statements that are based on boolean results). The most common conditional statements are if-else, unless, and ternary statements. given
statements are introduced as a switch-like construct from C-derived languages and are available in versions Perl 5.10 and above.
The basic structure of an if-statement is like this:
if (EXPR) BLOCK
if (EXPR) BLOCK else BLOCK
if (EXPR) BLOCK elsif (EXPR) BLOCK ...
if (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK
For simple if-statements, the if can precede or succeed the code to be executed.
$number = 7;
if ($number > 4) { print "$number is greater than four!"; }
# Can also be written this way
print "$number is greater than four!" if $number > 4;