for ( 0 .. $#numbers ) { push @{$h{$numbers[$_]}}, $strings[$_]; } for ( sort { $a <=> $b } keys %h ) { print join('', @{$h{$_}}), "\n"; }