my @things; push @things, [ $string, $index ]; # as many times as necessary for ( sort { $a->[1] <=> $b->[1] } @things ) { # do whatever with it, e.g. print: print "Index: $_->[1] String: $_->[0]\n"; }