my $string = "\t\t\tfoo\t\tbar"; $string =~ s/^(\t+).*/$1/; $string =~ s/\t/+1/g; print eval $string, " tabs";