use warnings; use strict; my @array; while (my $list = ) { # Remove trailing white-space, no need for chomp $list =~ s/\s+$//; # If the data is coming from a file (like this), # then you don't need to test defined if (defined $list and $list) { push(@array, $list); } } print "@array\n"; __DATA__ a b c d a a c d c