INPUT FILE = # comment # comment ON Mon, Tues, Fri, Sat # comment other stuff EXPECTED OUTPUT = $on = Mon,Tues,Fri,Sat CODE = #!/usr/bin/perl -w $infile = "test.txt"; $linecounter = 0; $inon = 0; $hold_on = ""; open(INFILE, $infile) || die "Can't open $infile : $!\n"; MAIN:while() $linecounter++; #printf("File Line %s = %s",$linecounter, $_); if ( /^\*/ || /^\#/ ) # Get rid of useless comments in file. { next MAIN; } chop; if ( /^on/i || $inon eq "1" ) { undef($tmpon); undef(@junk); if ( $inon eq "0" ) { @junk = split(' ', $_, 2); $tmpon = $junk[1]; $tmpon =~ s/\s//g; } else { $tmpon = $_; } $len = length($tmpon) - 1; $last_char = substr($tmpon, $len, 1); #printf("Last Char = %s\n", $last_char); if ( $last_char eq "," ) { $hold_on = "$hold_on$tmpon"; $inon = 1; next MAIN; } else { $on = "$hold_on$tmpon"; $inon = 0; $hold_on = ""; next MAIN; } } #other code printf("\$on = %s\n", $on); WISHFUL CODE = #$infile = "test.txt"; #$linecounter = 0; #open(INFILE, $infile) || die "Can't open $infile : $!\n"; #MAIN:while() # $linecounter++; # printf("File Line %s = %s",$linecounter, $_); # if ( /^\*/ || /^\#/ ) # Get rid of useless comments in file. # { # next MAIN; # } # chop; # if ( /^on/i ) # { # hold_on = ""; # undef(@junk); # @junk = split(' ', $_, 2); # $hold_on = $junk[1]; # $len = length($hold_on) - 1; # $last_char = substr($hold_on, $len, 1); # while ( $last_char eq "," ) # { # $read_line = readln(); # $read_line =~ chop($read_line); # $hold_on = "$hold_on$read_line"; # $len = length($hold_on) - 1; # $last_char = substr($hold_on, $len, 1); # } # $hold_on =~ s/\s//g; # } # #other code #printf("\$on = %s\n", $on);