#!/usr/bin/perl use strict; use warnings; chomp(my $HN = `hostname`); if (open(HOSTS, ") { next if ! /^((?:\d{1,3}\.){3}\d{1,3})\s+($HN)\b/; print "$2: $1\n"; last; } close HOSTS; } else { die "Could not open /etc/hosts for reading: $!\n"; }