You can do away with the hash completely by passing the order as a list rather than a string.
#! perl -slw
use strict;
sub munge {
my( $str, $regex ) = ( shift, shift );
my @matches = ( undef, $str =~ $regex );
return join'', @matches[ @_ ];
}
print munge(
'one_two_three',
'^([^_]+)_([^_]+)_([^_]+)$',
2, 1, 3
);
__END__
[10:24:12.59] P:\test>junk
twoonethree
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Time is a poor substitute for thought"--theorbtwo
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon