while () { if ( ( my $p = index( $_, "#" ) ) > -1 ) { substr( $_, $p, -1, "" ) } next if /^\s*$/; print; } __DATA__ #comment this is test#comment #comment this is test #comment this is test #comment this is test #comment