use strict; use warnings; use List::Util qw(uniq); my $given_string = '0ae4bb830'; my @results; foreach my $pos ( 0 .. 9 ) { foreach my $chr ( '0' .. '9', 'a' .. 'f' ) { my $out = $given_string; substr( $out, $pos, 0 ) = $chr; push @results, $out; } } { local $, = "\n"; print uniq(@results); }