#!/usr/bin/perl -w use strict; my $i = 1; my %list; open TEST, 'test.txt' || die "Couldn't open it"; print "\nFile Opened\n\n\n"; while(){ chomp; my ($f, $l) = split(' ', $_, 2); print "$i : $l\,$f\n"; $list{$i} = [$f,$l]; $i += 1; } foreach my $c (sort keys %list) { print "$list{$c}->[1],$list{$c}->[0]$/"; } close TEST; print "\n\n\nFile Closed\n";