use strict; use Data::Dumper; my @res = grep $_ split(",", "a,b,c,d,,f,,h"); print Dumper(\@res); my @res2 = grep { $_ } split(",", "a,b,c,d,,f,,h"); print Dumper(\@res2); #### $VAR1 = [ 'a', 'c' ]; $VAR1 = [ 'a', 'b', 'c', 'd', 'f', 'h' ];