foreach my $line (@text){ chomp($line); next if($line =~ /^\s*#/); #...do something with the non-commented lines }