use strict; use warnings; my $num = ; $num =~ s/hamu/1/g; $num =~ s/ham/0/g; print join('', map {$_ == 0 ? 'ham' : 'hamu'} split('', sprintf("%b", ord("0b".$num) * 2)));