while () { chomp; my @code; my @items = split /'/; until (not @items or $items[0] =~ s/--.*//) { @items and push @code, shift @items for 1, 2; } print join("'", @code), @items ? (@code ? "'" : q() ) . "$items[0]" : q(), "\n"; }