#!/usr/bin/perl package Dummy; use strict; use warnings; use overload '==' => \&iseq; sub new { return bless [ $_[1] ], $_[0];} sub iseq { return $_[0]->[0] == $_[1]->[0] ;} package MyTie; use strict; use warnings; use Carp; our $AUTOLOAD; sub TIEARRAY { my $class = shift; return bless [ map { Dummy->new($_) } @_ ], $class; } sub FETCH { $_[0]->[ $_[1] ]; } sub FETCHSIZE { scalar @{$_[0]}; } sub AUTOLOAD { croak "Undefined method $AUTOLOAD called in " . __PACKAGE__;} package main; use strict; use warnings; use Data::Dumper; use Devel::Peek; tie my @arr, 'MyTie', 1,3,4; for my $i (@arr){ for my $j (@arr){ # uncomment this row and comment out the next one, and it works # if($i->iseq($j)){ if($i == $j){ print $i->[0] . " == " . $j->[0] . "\n"; } else { print $i->[0] . " != " . $j->[0] . "\n"; } } } exit 0;