#!/usr/bin/perl -n BEGIN { @ARGV = (); $prev = ""; } chomp; if (defined $prev) { if ($prev eq "") { s/\s+$//; $proc = $_; undef $_; } elsif ($prev =~ /^\w+$/ && /^>\s*$/) { print "$proc -> $prev;\n"; undef $_; } elsif ($prev =~ /^\w+$/ && /^<\s*$/) { print "$prev -> $proc;\n"; undef $_; } elsif ($prev eq '>' && /^(\w+)\s*$/){ print "$proc -> $1;\n"; undef $_; } elsif ($prev eq '<' && /^(\w+)\s*$/){ print "$1 -> $proc;\n"; undef $_; } } $prev = $_;