my %email; my @parts = qw/From To Subject cc bcc body/; for my $part ( @parts ) { my $prompt = ( $part eq 'body' ) ? " (type EOT alone on a line to finish):\n" : ": "; print "Enter value for $part$prompt"; $email{$part} = ; if ( $part ne 'body' ) { chomp $email{$part} } else { while ( $email{$part} !~ /EOT\s+$/ ) { $email{$part} .= ; } s/EOT\s*$//; } } # add more parts to %email as you see fit (priority, port, etc) # (updated to fix logic so that chomp is applied where needed, # also fixed bad quotation mark and confusion in variable names, # and added deletion of "EOT" from $email{body})