in reply to @ Regular Expression

You are having issues with list vs. scalar context. When you write

my $machine_class = ($str =~ /MACHINE_CLASS=\s*(\w*)/);

Perl sees you are setting a scalar, and so interprets the right hand side in that context. Since the right hand side is a list, it assigns the size of the list (1) to $machine_class. You can put the assignment in list context by wrapping your variable in parentheses:

my ($machine_class) = ($str =~ /MACHINE_CLASS=\s*(\w*)/);

See Extracting matches in perlretut. You can read more about context in Perl in Context in perldata or Context tutorial from the Tutorials.