#!/usr/bin/perl use MIME::Base64; my $image; my $buf; while(<>) { if (//) { $image= $1; $buf = ''; } elsif (/<\/image>/ ) { open(OUT, ">/tmp/$image") ; print OUT decode_base64($buf); $image = ''; } elsif ($image) { $buf .= $_; } }