#!usr/bin/perl open (FILE, "raj.txt") || die "Cannot open file.\n"; open (NEWFILE, ">rk.txt") || die "Cannot find or open file for editing.\n"; my %count; while (my $line=) { my @z = (split(/\n/,$line)); ++$count{$z[0]}; } print "\n\tGRADES SORTED BY STUDENT NAME:\n"; foreach $key (sort (keys(%count))) { print NEWFILE "\t\t$key \t\t$keys{$values}\n"; } close NEWFILE; close FILE; print "Done!\n";