#! perl -slw use strict; use Algorithm::Combinatorics qw[ variations_with_repetition ]; sub zip { my( $r1, $r2 ) = @_; my $n = @$r1 > @$r2 ? $#{$r1} : $#{$r2}; map{ ( $r1->[ $_ ] // '', $r2->[ $_ ] // '' ) } 0 .. $n; } sub dashedCombos { my @words = split ' ', shift; map { join '', zip( \@words, $_ ) } variations_with_repetition( [ ' ', '-' ], $#words ); } print for dashedCombos( 'convert perl to python' ); __END__ C:\test>1137970 convert perl to python convert perl to-python convert perl-to python convert perl-to-python convert-perl to python convert-perl to-python convert-perl-to python convert-perl-to-python