#!/usr/bin/perl # http://perlmonks.org/?node_id=1128230 use strict; $_ = '00111'; 1 while print("$_\n"), s/.*\K01(.*)/10 . reverse $1/e;