#!/usr/bin/perl use strict; use warnings; package State; use Moose; has 'x' => ( is => 'rw', isa => 'ArrayRef' ); has 'y' => ( is => 'rw', isa => 'ArrayRef' ); has 'z' => ( is => 'rw', isa => 'ArrayRef' ); sub compare { my $self = shift; my $other = shift; my $is_equal = 1; for (sort keys %$self) { $is_equal = 0 unless _arr_eq( $self->{$_}, $other->{$_} ) } return $is_equal; } sub _arr_eq { my $arr1 = shift; my $arr2 = shift; return '0' if $#$arr1 != $#$arr2; my $is_equal = 1; for (0 .. $#$arr1) { $is_equal = 0 unless ($arr1->[$_] eq $arr2->[$_]); } return $is_equal; } package main; use Data::Dumper; my $master = new State ( x => ['1','a'], y => [], z => ['4'], ); my $h1 = new State ( x => ['1','a'], y => [], z => ['4'] ); my $h2 = new State ( x => ['a'], y => [], z => ['1'] ); print "\$h1 is identical.\n" if $master->compare($h1); print "\$h2 is identical.\n" if $master->compare($h2);