#!PERL.EXE -w
use strict;

print "Enter the price not necessarily in the format of \"\$123.45\" (^Z to quit)\n";
while (1) {
    print "\n\n> ";
    my $line=<STDIN>;
    $line or last; #   unless ($line) { last; }
    chomp($line);

    # $i              12  3        45    6  7
    if ( $line =~ m/\b((\.(\d{2}))|((\d+)(\.(\d{2}))?))\b/ )
    {
        print "EXTRACTED: number $1 which is ";
        if (defined($2)) #the first of two formats was matched
        {
            print "no dollars and $3 cents ";        
        } else { # defined($4) since if is true - something must have matched
            if (defined($6)) # cents in the second format were matched
            {
                print "$5 dollars and $7 cents ";        
            } else {
                print "$5 dollars and no cents ";        
            }
        }
    }
    else
    {
        print "WRONG PRICE FORMAT!\n";
    }
}