#!/usr/bin/env perl -l use strict; use warnings; { local $/ = "\ndn: "; while () { / ^ cn: \s+ (.*?) $ .*? ^ orclnetdescstring: \s+ (.*?) $ /msx; print join '=', $1, $2; } } __DATA__ dn: distinguished_name1 cn: common_name1 orclnetdescstring: complex_address_line1 dn: distinguished_name2 cn: common_name2 orclnetdescstring: complex_address_line2 dn: distinguished_name3 cn: common_name3 orclnetdescstring: complex_address_line3 #### common_name1=complex_address_line1 common_name2=complex_address_line2 common_name3=complex_address_line3