use strict; use warnings; sub RemoveComments { my $line=$_[0]; if ($$line =~ /#/){ $$line =~ s/#.*$//; } if ($$line =~ /^\s*$/){ return 1; } } .... while ($temp=){ my $empty =0; $empty=&RemoveComments(\$temp); if ($empty == 1){ next; } ... some other code ... }