I have perl code which should do some action only if: - the variable does not begin with "#" (commented out), - the variable is not empty use strict; use warnings; my @array = ("# Comment", "/usr/bin/binary --test", ""); foreach my $var (@array) { my @execargs = split(/#/, $var); if ( $execargs[0] ne '' ) { print "$var 0: $execargs[0] \n" }