Maybe its because its after midnight and I have been coding all day, who knows, but I am not really sure what you are wanting to do.
That aside though, I took and modified your regex (only slightly), at the behest of the Komodo editor that I am using. Here is the quick script I wrote:
-
use strict;
-
use warnings;
-
-
print("Please input a string: ");
-
my $input = <STDIN>;
-
chomp($input);
-
-
$input =~ s/(\-*\d+\.\d+)/foo$1bar/g;
-
-
print("$input");
-
Now, I ran the script a few times, using the input you provided. You can see here what the script produced:
######## Script Output ############
C:\>perl select.pl
Please input a string: foo1.2bar.3
foofoo1.2barbar.3
C:\>perl select.pl
Please input a string: 1.2.3
foo1.2bar.3
C:\>perl select.pl
Please input a string: 1.23
foo1.23bar
C:\>perl select.pl
Please input a string: -12.34
foo-12.34bar
C:\>
######## End Output #############
I addeed blank lines here manually for readability of the output. As you can see, I think it did what you wanted, but again, I wasn't quite sure what you were looking for.
If this isn't what you wanted, maybe you could elaborate a fair amount and provide better examples of what you are trying to achieve.
Regards,
Jeff