my @special_chars = qw( : ; , = - ); my $special_chars_glob_alt = "{".( join ",", map quotemeta, @special_chars )."}"; my $corrupt_qfn = ...; my $glob = $corrupt_qfn =~ s{ ( [ ] ) | ( [^\w ] ) }{ defined( $1 ) ? $special_chars_glob_alt : "\\$2" }xegr; my @possible_qfns = glob( $glob ); say for @possible_qfns; #### use Algorithm::Loops qw( NestedLoops ); my @special_chars = qw( : ; , = - ); my $corrupt_qfn = ...; my $iter = NestedLoops([ map { $_ eq " " ? \@special_chars : [ $_ ] } split( /( )/, $corrupt_qfn, -1 ) ]); while ( my @parts = $iter->() ) { my $possible_qfn = join( "", @parts ); say for $possible_qfn; }