use strict; my @arrayone = ('anu','abu','ali'); my @arraytwo = ('anu','abu'); my $arrays_match_result=match_arrays(\@arrayone,\@arraytwo); if($arrays_match_result==1) { print "Array's are the same\n"; }else{ print "Array's are not the same\n"; } sub match_arrays { my ($array1,$array2)=@_; my $el2cnt=0; my $not_the_same; for my $el1 (@$array1) { unless ($el1 eq @$array2[$el2cnt]) { $not_the_same=1; } $el2cnt++; } if($not_the_same==1) { return 0; }else{ return 1; } }