There are 5 comments, 4 white space and 12 lines of code in this file here are just code lines: 1: $|=1; 2: print "content-type: text/plain\n\n"; 3: $str = '^#'; # regexp to count full-line comments, starting with # 4: $ARGV[0]= $0; # slurp this 5: @lines=<>; # file 6: $n = grep /$str/, @lines; # number of comments 7: @m = grep !/$str/, @lines; # all non-comments 8: @c = grep !/^\s*$/, @m; # all code lines 9: $s = grep /^\s*$/, @m; # all white-space lines 10: print "There are $n comments, $s white space and ", scalar(@c), " lines of code in this file \n"; 11: print "here are just code lines: \n"; 12: for (@c) { $i++; print "$i: $_";}