my $i=0; { ... last if ; $i++; redo; } my $x = substr $somestring, 0, $i;