Apart from reworking your code a little to avoid external file usage, the following should point you in the right direction:

use strict; use warnings; my $converted; my $discarded; my $holder; my @report; $converted=0; $discarded=0; sub report { my ($original, $result) = @_; $original =~ tr/\n//d; if (defined $result) { $result =~ tr/\n//d; push @report, "$original -> $result\n"; $converted++; } else { push @report, "$original\n"; } } while (<DATA>) { my $line = $_; if ($line =~ /\bMOVE\s(\d+)\sTO\s(\w+)/) { $line = "$2 := $1;\n"; report ($_, $line); } elsif ($line =~ /\bDISPLAY\s'([^']*)'\./) { $line = "PUT(\"$1\");\n"; report ($_, $line); } elsif ($line =~ /\bDISPLAY\s(\w+)\./) { $line = "PUT($1);\n"; report ($_, $line); } else { $discarded++; } print $line; } report ("No. of Keywords Converted: $converted\n"); report ("No. of Keywords Discarded: $discarded, \n"); print "------------------8<----------------------\n"; print @report; __DATA__ MOVE 4 TO INT1. DISPLAY 'MEMBERS OF THE GROUP'. DISPLAY INT1. ADD 5 TO INT4

Prints:

INT1 := 4; PUT("MEMBERS OF THE GROUP"); PUT(INT1); ADD 5 TO INT4 ------------------8<---------------------- MOVE 4 TO INT1. -> INT1 := 4; DISPLAY 'MEMBERS OF THE GROUP'. -> PUT("MEMBERS OF THE GROUP"); DISPLAY INT1. -> PUT(INT1); No. of Keywords Converted: 3 No. of Keywords Discarded: 1,

DWIM is Perl's answer to Gödel

In reply to Re: switching parts of a text by GrandFather
in thread switching parts of a text by oblate kramrdc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.