my @array = qw( wilma fred barney betty ); foreach my $i ( 0 .. $#array ) { print "$array[ $i ] is the current element.\t"; print "The next element is "; # Before using the next element, test for its existence. print exists $array[ $i + 1 ] ? $array[ $i + 1 ] : "unprintable" ; print ".\n"; # An approach more to your liking might be: # if ( exists $array[ $i + 1 ] ) { # or: # last if $i == $#array; # or: # print $array[ $i + 1 ] unless $i == $#array; # }