my $record = ''; while (<>) { # read a line of input data s/\s+$/ /; # normalize all line-final whitespace to " " $record .= $_; if ( /\\ $/ ) { # if line ended with a backslash $record =~ s/\s*\\ / /; # remove it from the record, next; # and move on to add next line } # if ( $record !~ /find/ ) { # if record doesn't have this # next; # try adding next line # } # now just figure out what to do with $record -- e.g. my @tokens = split ' ', $record; $record = ''; # in case there's another record coming print "\n", join( ' ', @tokens ), "\n"; # just guessing here, about what might be useful... my %params = (); $params{cmd} = shift @tokens; $params{amount} = shift @tokens if ( $params{cmd} =~ /set/ ); my $lastparam; while ( @tokens ) { $_ = shift @tokens; if ( /^-/ ) { $params{$_} = ''; $lastparam = $_; } elsif ( /find\W+port\W+(\w+)/ ) { $params{port} = $1; last; } else { $params{$lastparam} = $_; } } for ( sort keys %params ) { print "$_ => $params{$_}\n"; } print "\n"; }