#! perl use strict; use warnings; { package Student; sub new { my ($class, $name, $age, $regd_no, $phone_num, $mark, $pass_year) = @_; my $self = { NAME => $name, AGE => $age, REGD_NO => $regd_no, PHONE_NUM => $phone_num, MARK => $mark, PASS_YEAR => $pass_year }; return bless $self, $class; } sub display { my ($self) = @_; if ($self) { print 'Name: ', $self->{NAME}, "\n"; print 'Age: ', $self->{AGE}, "\n"; print 'Regd no: ', $self->{REGD_NO}, "\n"; print 'Phone num: ', $self->{PHONE_NUM}, "\n"; print 'Mark: ', $self->{MARK}, "\n"; print 'Pass year: ', $self->{PASS_YEAR}, "\n"; } } } my @students; while () { chomp; push @students, Student->new(split /:/); } find_student('x3')->display(); sub find_student { my ($regd_no) = @_; for (@students) { return $_ if $_->{REGD_NO} eq $regd_no; } return undef; } __DATA__ A:20:x1:phone4:72:2011 B:19:x2:phone2:55:2012 C:22:x3:phone3:83:2009 D:23:x4:phone1:69:2008