#!/usr/bin/perl use warnings; use strict; # # Open file for reading (explicit), die on error # open SERVICES, '<', '/etc/services' or die "cannot open /etc/services: $!"; # # Read thru each line (put into $_), and print the captured # comment text if the line has a comment (anything after a # # to the end of line). Note that this doesn't include the # hash (pound, octothorpe, et al.); move it inside the parens # for that behavior. # while () { print "$1\n" if /#(.*)$/ } # Close filehandle close SERVICES;