#!usr/bin/perl use strict; # don't leave home without it use warnings; # same here! use 5.10.0; # so you can use say() my @ports = qw( 21 22 23 ); # make a hash from the array for easier lookup my %ports = map { $_ => 1 } @ports; # use a lexical variable for your filehandle open my $SERVICES_FILE, '<', '/etc/services' or die $!; # read one line at a time with while() while ( my $line = <$SERVICES_FILE> ) { # deal with new-line character at end of line chomp( $line ); # 'postfix if' simplifies syntax say "Match Found: $line" if $ports{ $line }; } # good practice to close filehandle close $SERVICES_FILE or die $!; # good practice to tell Perl when the program's done __END__