use strict; use warnings; my %details; my @rules=( "Hardware" => sub{$details{HARDWARE_SEEN} = 1 }, 'cisco Nexus (\S+)' => sub{return 0 unless $details{HARDWARE_SEEN}; $details{Chassis} = $_[0]; }, 'Intel.+?(\d+)\s*(\w{2}) of memory' => sub{ return 0 unless $details{HARDWARE_SEEN}; $details{"Main Memory"} = $_[0]; $details{"Main Memory Unit"} = $_[1]; }, ); while (){ for (my $i=0; $i < $#rules; $i+=2){ my $regex=qr|$rules[$i]|; my $action = $rules[$i+1]; next unless m/$regex/i; last if $action->($1,$2,$3); } } for (sort keys %details){ print "$_\t = $details{$_}\n"; } __DATA__ # Sample output # Hardware # cisco Nexus 3048 Chassis ("48x1GE + 4x10G Supervisor") # Intel(R) Celeron(R) CPU P450 with 3981680 kB of memory.