$line = " This is the test line"; if( $line =~ /(\S)/ ){ # match first non-space character print index($line, $1),"\n"; # find index } __END__