Example: Object => Dependency 1 => undef (no dependency) 2 => 4 3 => 5 4 => 3 5 => 1 #### sub sortPatch { my %ArgHash=@_; my $version = join('',keys(%ArgHash)); my @tbs = split(/\,/,$ArgHash{$version}); my @LoopControl=@tbs; my @returning; foreach (@tbs,(1)) # this should make it go one more time... right? { my ($previous,$patchlist); foreach my $patch (@LoopControl) { undef($previous); undef($patchlist); $previous=$PatchInfo::patch{$version}{$patch}{'PREVIOUS'} if (defined($PatchInfo::patch{$version}{$patch}{'PREVIOUS'})); $patchlist = join('|',@returning); if (defined($previous)) { if (($previous ne '') and (not($previous =~ /$patchlist/))) { my $selected = join('|',@tbs); if (($previous =~ /$selected/) and ($selected ne '')) { push(@returning,$previous); } } } push(@returning,$patch); } @LoopControl=(); @LoopControl=@returning; } return @returning; }