#!/usr/bin/perl $string = "1"; # Infinite loop caused by modifying the string we are matching against in while statement while ($string =~ /(\d)/g) { $match = $1; $string =~ s/$match/$match/; } print $string;