perl -Mstrict -Mwarnings -le ' sub tab { return q{ } x 4; } foreach my $s ( q(hoststatus {), tab . q{host_name=AAA1}, tab . q{modified_attributes=0}, tab . q{check_command=check-host-alive}, tab . q{check_period=24x7}, tab . q{notification_period=24x7}, tab . q{check_interval=5.000000}, tab . q{retry_interval=1.000000}, tab . q(}), q{}, q(servicestatus {), tab . q{host_name=AAA1}, tab . q{plugin_output=eth0:UP, eth2:UP, eth3:UP, eth1:UP:4 UP: OK}, tab . q(}) ) { print $s; } ' \ | \ perl -Mstrict -Mwarnings -MData::Dumper -lne ' use vars qw(%s); BEGIN{ $Data::Dumper::Deepcopy = $Data::Dumper::Sortkeys = 1; }; chomp; if ( m/\}/ ) { print Data::Dumper->Dump( [ \%s, ], [ qw( *s ) ] ); %s = (); } next if ( m/^\s*$/imsx ); $s{TYPE} = $1 if ( m/^\s*(\S+)\s*\{/imsx ); $s{$1} = $2 if ( m/^\s+([^=]+)=(.+)$/imsx ); ' #### %s = ( 'TYPE' => 'hoststatus', 'check_command' => 'check-host-alive', 'check_interval' => '5.000000', 'check_period' => '24x7', 'host_name' => 'AAA1', 'modified_attributes' => '0', 'notification_period' => '24x7', 'retry_interval' => '1.000000' ); %s = ( 'TYPE' => 'servicestatus', 'host_name' => 'AAA1', 'plugin_output' => 'eth0:UP, eth2:UP, eth3:UP, eth1:UP:4 UP: OK' );