#!/usr/bin/perl use strict; use warnings; my @nme; # Input loop while ((print "Enter the name: "), defined (my $input = )) { chomp $input; last if ! length $input; # Exit loop on empty line my ($fn, $ln) = split /\s+/, $input, 2; if (! defined $fn) { print "Blank name ignored\n"; next; } $ln ||= '_missing_'; # Provide missing name print "$fn, $ln\n"; push @nme, "$ln, $fn"; } # Print loop print "$_\n" foreach sort @nme;