$block_comment = 0; while ( ) { if ( m{^//} ) { next; } elsif ( m{^/\*} ) { $block_comment = 1; next; } # start block elsif ( m{^\*/} ) { $block_comment = 0; next; } # end block elsif ( $block_comment) { next; } # inside block else { ... do something with the line, that is no comment ... } }