How can we break out from a loop in perl?

It’s can be done as :-

my @a=(1,2,3,4,5,6,7,8,9,12);
my $b=3;
#print "ttt:-".$a[$b-2];
foreach my $c (@a)
{
    print $c."\n";
    if($c==$b)
    {
        last;
    }
}

The output will be as :

  1
 2
 3

Leave a Reply