What would be the most efficient way to write the following code in Perl:
my $index = 0;
foreach ( @spec ) {
if ( $module =~ m/$_/ ) {
splice(@spec, $index, 0, $module);
last;
}
$index++;
}
This works fine but just seems a little wordy. The idea is that where I find a match for $module in the array I add an entry. I want to keep the array in a certain order and sorted.