#!/usr/bin/perl use strict; my @lines = <>; my $output = ''; while(@lines) { my $chords = shift @lines; if($chords =~ /^\s*$/) { $output .= "\n"; next; } my $lyrics = shift @lines; my $chord_offset = 0; my $lyric_offset = 0; while($chords) { print STDERR "Chord offset: $chord_offset\tLyric offse: $lyric_offset\n"; print STDERR "Chords: <$chords>\n"; print STDERR "Lyrics: <$lyrics>\n"; if($chords =~ s/^(\s+)//) { $chord_offset += length $1; } if($chords =~ s/^(\S+)//) { my $chord = $1; $chord_offset += length $chord; $chord = "[$chord]"; substr($lyrics, $lyric_offset + $chord_offset, 0, $chord); $lyric_offset += length $chord; } } $output .= "$lyrics"; } print $output;