#!/usr/bin/perl use strict; use warnings; open my $hostsIn, '<', "/etc/hosts" or die "Cannot open hosts file! \n"; my @hosts = <$hostsIn>; close $hostsIn; foreach my $line (@hosts) { next if $line !~ /($ARGV[0])/; print $line; $line = undef; }