my $i; for $i ( 0 .. 10 ) { last if ; ... } my $x = substr $somestring, 0, $i;