#!/usr/local/bin/perl use strict; use warnings; use Data::Dumper; my $file = "C:/Documents and Settings/franciscor/Desktop/Kindergarten.txt"; open my $fh, '<', $file or die("Error opening file $!"); my %students_51; my %students_53; until ( eof($fh) ) { chomp( my $name = <$fh> ); chomp( my $age = <$fh> ); chomp( my $topic = <$fh> ); chomp( my $class = <$fh> ); if ( $class == 2051 ) { $students_51{$name}->{'age'} = $age; $students_51{$name}->{'topic'} = $topic; $students_51{$name}->{'class'} = $class; } elsif ( $class == 2053 ) { $students_53{$name}->{'age'} = $age; $students_53{$name}->{'topic'} = $topic; $students_53{$name}->{'class'} = $class; } } close $fh; print Dumper(\%students_51,\%students_53);