use strict; my $ha = [[1,2], [5,5,5], [1,2], [3,4]]; my $hb = [[4,3], [2,1], [1,2], [5,5,5]]; sub test { my ($ha, $hb) = @_; my ($tha,$thb) = ([],[]); for( @{ $ha } ) { push @{$tha},[ sort @{$_} ]; } $tha = [ sort { $a->[0] <=> $b->[0] } @{$tha} ]; for( @{ $hb } ) { push @{$thb},[ sort @{$_} ]; } $thb = [ sort { $a->[0] <=> $b->[0] } @{$thb} ]; use Data::Dumper; return Dumper($tha) eq Dumper($thb); } print test($ha,$hb);