say "$_ => [", (m/(\d*\.?+\d*)/x ? "$1]" : ']'); # ^ #### #! perl use strict; use warnings; use feature qw( say ); my $decimal = qr{ ( (?: \d+ \.? \d* ) | (?: \d* \.? \d+ ) ) }x; while () { chomp; next unless length; say "$_ => [", (/$decimal/x ? "$1]" : ']'); } __DATA__ 0.12 .12 12. 12 no numbers here abc.def42 .7zx #### 16:39 >perl 1621_SoPW.pl 0.12 => [0.12] .12 => [.12] 12. => [12.] 12 => [12] no numbers here => [] abc.def42 => [42] .7zx => [.7] 16:39 >