# prepare regex sub-expressions my $sizerx = '(-|\d+(\.\d+)?[GM]?)'; # Matches '-', or a float + 'M' or 'G' for size my $loadrx = '(-|\d+\.\d\d)'; # Matches '-' or a float my $procrx = '(-|\d+)'; # matches '-' or an integer # Test the line to see if it matches if( $_ =~ /^(\w+)\s+ # host (\w+)\s+ # os $procrx\s+ # nproc $loadrx\s+ # load $sizerx\s+ # memtot $sizerx\s+ # memuse $sizerx # swapto \s*$ /x ) { print "using regex, host is [$1]\n"; }