#!/usr/bin/perl use warnings; my @array = ("One", "Two", "Three", undef, "Five", "Six"); my @newarray = (); foreach my $element (@array) { last unless defined ($element); push @newarray, $element; } foreach (@newarray) { print $_." \n"; }