sub leftover{ my ($full, $part) = @_; while ($full && $part) { #RexExp to substitute nothing for the first match #then remove the matched character from $part } }