#!/usr/bin/perl -w use strict; my @hosts = qw(localhost); HOST: foreach my $host (@hosts ) { open(NMAP, "nmap -O $host |") || next; while() { chomp; if(/Remote operating system guess: (.*)/) { print "$host $1\n"; next HOST; } } }