#!/bin/perl -w use strict; $/="|--------------------------------------|\n"; ; # skip the first (empty) record before the first |---| line while( ) # read an entire record { chomp; # to get rid of the extra \n that would mess up the split my %data= (m/^([^:]*):([^\n]*)$/mg); # get field name (before the :) and text (until the \n) for each line # %data now holds the fields and their text, and I prove it: while( my( $field, $text)= each %data) { print "$field: $text\n"; } print "\n"; } __DATA__ |--------------------------------------| Date: today Request: text here text here text here Name: Joe Bloggs Tel: 0123 45677 email: joebloggs@bloggs.com |--------------------------------------| Date: Today Request: text here text here text here Name: John Smith Tel: 0123 45677 email: johnsmith@smith.com |--------------------------------------|