You'll become an expert, if you use Perl a lot.

If you use Perl a lot, you'll become an expert.

These two sentences mean the same and if we are told either of those we'll understand the same thing. Maybe there is a slight difference in the focus of the sentence, but the real meaning is the same.

Just as in English and in any other spoken language you can do the same reversal in Perl as well.

if-statement in Perl

These two examples do the same in Perl:

if (-e $file) {
    die "File '$file' already exists";

die "File '$file' already exist" if -e $file;

In both cases Perl first checks the condition (does the file $file exist?), and in both cases it executes the die statement only if the condition was met.

You are already familiar with the first, the direct way of writing an if-statement and the block that belongs to it. In the second example we reversed the order of the two parts. We could also leave out the curly-braces of the block {}, and the parentheses () of the condition. That's the big advantage of writing this way.

The disadvantage is that in this syntax there can be only one statement in the (not existing) block. There can be only one statement executed if the condition was met and there is no else part at all.

This kind of statement is often used together with flow-control statements such as die, next, and last, to name a few.

unless-statement in Perl

Just as if can be used as a statement modifier, we can also use unless as a statement modifier.

if (not -e $file) {
    die "File '$file' does not exist";

Is the same as

unless (-e $file) {
    die "File '$file' does not exist";

Which is the same as

die "File '$file' does not exist" if not -e $file;

which is the same as:

die "File '$file' does not exist" unless -e $file;