#!/usr/bin/perl -w use strict; use Data::Dumper; my @AoH; while () { make_AoH_entry() if (/^define service{/); } print Dumper(\@AoH); sub make_AoH_entry { my %hash; while ( (my $line=) !~ /^}/ ) { next if ($line =~ m/^\s*$/); my ($name, $value) = ($line =~ m/\s*(\w+)\s+(.*)$/); $hash{$name} = $value; } push (@AoH, \%hash); } #================== #Prints: #$VAR1 = [ # { # 'use' => 'sam_win_cpu_load', # 'host_name' => 'buo.va.com', # 'contact_groups' => 'buo_admins' # }, # { # 'check_command' => 'check_service_state!MSSQLSERVER!public', # 'service_description' => 'MS SQL Server', # 'use' => 'generic-service', # 'host_name' => 'buo.va.com', # 'contact_groups' => 'buo_admins' # } # ]; __DATA__ define service{ use sam_win_cpu_load host_name buo.va.com contact_groups buo_admins } define service{ use generic-service host_name buo.va.com service_description MS SQL Server check_command check_service_state!MSSQLSERVER!public contact_groups buo_admins }