my $state = 'declaration'; my( $name, %data ); while( <> ) { if( $state eq 'declaration' ) { if( /CALCON\((.*?)\)/ ) { $name = $1; $state eq 'opencurly'; next; } } if( $state eq 'opencurly' ) { $state = 'body' if /{/; } if( $state eq 'body' ) { if( /(\S+)\(.*?\)\s*$/ ) { $data{ $name }->{ $1 } = $2; } if( /\s*}\s*$/ ) { $state = 'declaration'; } } }