while ($line = <>) { # redo comes HERE # do something my $next = <>; if ($next !~ /^#/) { # if the next line DOES NOT start with a "#" # reuse it and restart this iteration of the loop $line = $next; redo; } }