#! /usr/bin/perl -l use strict; use warnings; my @array = ( 1..3 ); my $max = 5; for ( @array[0..$max-1] ) { last if !defined; print; }