The \G anchor means "anchor to where the last //g match left off". When no global match has been done yet, \G is synonymous to ^. Thus, each leading space is turned into a colon until a space is not found following the last one.$str =~ s/\G\s/:/g;
In reply to Re: substitute leading whitespace
by japhy
in thread substitute leading whitespace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |