#!/usr/bin/env perl use strict; use warnings; use Data::Dumper; my %parts; my $key; while (my $line = ) { if ($line =~ /^([A-Z]+)$/) { $key = $1; if ($key =~ /^END/) { undef $key; } next; } next unless defined $key; $parts{$key} //= ''; $parts{$key} .= $line; } print Dumper (\%parts); __DATA__ TO rahul@example.com,you@everyone.com ENDTO SUBJECT Weekly status snapshot for WW-5 ENDSUBJECT BODY Hi All, Weekly progress snapshot for this week will be taken on Thursday, 30 Jan at the end of the day. ( Please update your status before the snapshot) Use work week number as 5 for this week's updates . Note : If you want any additional data to be picked up ( or dropped ) from your sheets, do work with me so that status collation script can be updated to do this . Thanks , -Ram ENDBODY