#! /usr/bin/perl use strict; use warnings; my $hn = 'localhost.localdomain'; my $hosts = `cat /etc/hosts`; if ( $hosts =~ /^([\d\.]+)\s+($hn)/mg ) { print "true: $1 $2\n"; } else { print "false!\n"; }