$changed = 0; my @array = sort { my $result = ($a cmp $b); $changed = 1 if $result==1; # Only set changed if $a > $b $result } @oldarray;