#!/usr/bin/perl use strict; use warnings; # Might as well declare this early on and save some typing :) my $s = "students.txt"; # *Always* check system operations for errors open Fh, ">", $s or die "$s: $!\n"; print Fh "Perry*Steve*234\nSmith*Jane*456\nJones*Mary*567\n"; close Fh; my (@bits, %pass); # Don't guess at the error ahead of time - get the real story with '$!' open Fh, "<", $s or die "$s: $!\n"; while() { @bits = split /\*/; $pass{join "_", @bits[0,1]} = $bits[2]; } # Let's see what we got in the hash printf "%s:\t%d\n", $_, $pass{$_} for sort keys %pass;