while(){ chomp; next unless length; say "$_ => [", (m/(\d*\.?+\d*)/x ? "$1]" : ']'); } __DATA__ 0.12 .12 12. 12 #### 0.12 => [0.12] .12 => [.12] 12. => [12.] 12 => [12] #### m/( \d* \.?+ \d* )/x # Mine m/( \d* \.? \d+ )/x # Yours