sub insertAfter{ use List::Util qw[ first ]; my( $aref, $before, $insert ) = @_; my $first = first{ $aref->[ $_ ] eq $before } 0 .. $#$aref ; return unless defined $first; splice @{ $aref }, ++$first, 0, $insert; }