last cannot be used to exit a block that returns a value such as eval {}, sub {}, or do {}, and should not be used to exit a grep() or map() operation.
Note that a block by itself is semantically identical to a loop that executes once. Thus last can be used to effect an early exit out of such a block.
So, last doesn’t work in a do { ... } until (...); loop. But — put the whole construct inside a block, and last now works fine:
#! perl
use strict;
use warnings;
my $n = 42;
{
do
{
printf "n = %d\n", $n--;
last if $n == 37;
} until ($n <= 0);
}
print "Past the loop\n";