while( my $line = ) { while (1) { chomp( $line ); last if $line !~ /^#/; } print "Doesn't begin with #\n"; }