#!/usr/bin/perl -w

# Usage:
#   Perl format1.pl outputfile

# Set up format.
format NAMES=
Last name : @<<<<<<<<<<<<<<<<<<<<
$lastname
First name: @<<<<<<<<<<<
$firstname

.
# Note period alone on line above.
# Also note blank line before period.

open(NAMES, ">yourFile.txt" ) or die "Can't open yourFile.txt, $!";

$lastname  = "AA";
$firstname = "BB";
write NAMES;
$lastname  = "FF";
$firstname = "MVV";

write NAMES;
close(NAMES);