#!/usr/bin/perl use warnings; use strict; sub output { my ($id, @jobs) = @_; print join("\t", $id, @{$_}{qw(JOBID TYPE FILE)}), "\n" for @jobs; } my @jobs; my $id; while (<>) { my ($tag, $value) = m{<(.*)>(.*)} or next; if ('PROJECT_ID' eq $tag) { output($id, @jobs); $id = $value; @jobs = (); } else { $tag =~ s/[0-9]+$//; $#jobs++ if 'JOBID' eq $tag; $jobs[-1]{$tag} = $value; } } output($id, @jobs); # Don't forget to output the last job.