#!/usr/bin/env perl use strict; use warnings; my $comment_line_re = qr{ \A \s* [#] }x; while () { print "@{[/$comment_line_re/ ? 'IS' : 'NOT']} Comment: $_"; } __DATA__ # This file is a comment and should not be used # This comment has one leading space # This comment has three leading spaces /dev/mapper/centos-var_log /var/log xfs defaults 1 2 /dev/donstest /expert none 1 1 -rw,noglob # this is a fs #/dev/donstest22 /expert none 1 1 -rw,noglob # this is a fS #### $ pm_1124511_comment_removal.pl IS Comment: # This file is a comment and should not be used IS Comment: # This comment has one leading space IS Comment: # This comment has three leading spaces NOT Comment: /dev/mapper/centos-var_log /var/log xfs defaults 1 2 NOT Comment: /dev/donstest /expert none 1 1 -rw,noglob # this is a fs IS Comment: #/dev/donstest22 /expert none 1 1 -rw,noglob # this is a fS