What is if-else statement in Perl?
Conditions allow the coder to alter the execution flow by deciding which block of code should be executed. The if-else statement is an extended version of an if statement that provides an alternate path of execution in case the if statement condition does not hold true.
Syntax
if(condition) {
#if the condition is true execute this block
}
else {
#execute this if condition is not met and
}
Code
The following code shows how the if-else statement in Perl is used.
$num1 = 200;if( $num1 <=100 ) {printf "First number is less than or equal to than 100\n";}else{printf "First number is greater than 100\n";}$num1 = 50;if( $num1 <=100 ) {printf "Second number is less than or equal to than 100\n";}else{printf "Second number is greater than 100\n";}
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved