#! /usr/bin/perl -w use strict; my %lookup; my %invert; my @base = qw(a c g t); my $count = 0; for my $x1 (@base) { for my $x2 (@base) { for my $x3 (@base) { for my $x4 (@base) { my $key = chr($count++); my $chunk = "$x1$x2$x3$x4"; $invert{$key} = $chunk; $lookup{$chunk} = $key; } } } } for my $seq (@ARGV) { print "squeeze => ", squeeze($seq), "\n"; print "unsqueeze => ", unsqueeze($seq), "\n"; } sub squeeze { my $seq = shift; my $out = ''; $out .= $lookup{lc $1} while ($seq =~ /(....)/g); return $out; } sub unsqueeze { my $seq = shift; my $out = ''; $out .= $invert{$_} for split //, $seq; return $out; }