#! /usr/bin/perl -w use strict; my $want_next_line = 0; my $on = ''; while( ) { chomp; # never use chop s/\s*#.*$//; # discard comments next unless $_; # go to next line if nothing left if( /^on (.*)$/i ) { $on = $1; } elsif( $want_next_line ) { $on .= $_; } $want_next_line = $on =~ /,$/ ? 1 : 0; } $on =~ s/\s//g; print "\$on = $on\n"; __DATA__ INPUT FILE = # comment # comment ON Mon, Tues, Fri, Sat # comment other stuff